| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515 |
- package com.mes.ui;
- import com.alibaba.fastjson2.JSONObject;
- import com.mes.component.MesRadio;
- import com.mes.component.MesWebView;
- import com.mes.component.ProductTypePanel;
- import com.mes.netty.NettyClient;
- import com.mes.util.ClientVersionUtils;
- import com.mes.util.ClientUpgrade;
- import com.mes.util.*;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import javax.print.PrintService;
- import javax.print.PrintServiceLookup;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import javax.swing.table.DefaultTableCellRenderer;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableColumn;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.time.LocalDateTime;
- import java.util.*;
- import java.util.List;
- import java.util.Timer;
- public class MesClient extends JFrame {
- public static final Logger log = LoggerFactory.getLogger(MesClient.class);
- private static String Drivde = "org.sqlite.JDBC";
- public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
- public static String mes_gw = "OP280A"; // 工位号
- public static String mes_gw_des = ""; // 工位名称
- public static String mes_server_ip = ""; // 服务器IP地址
- public static int mes_tcp_port = 3000; // TCP服务端口
- public static int mes_heart_beat_cycle = 10; // 心跳周期
- public static int mes_heart_icon_cycle = 1;
- public static String mes_line_sn = "";
- public static String client_version = "0.0.0"; // 打包发布版本,需和后台 JAR 管理版本号对齐 // 产线编号
- //TCP连接
- public static NettyClient nettyClient;
- //TCP连接状态
- public static boolean tcp_connect_flag = false;
- //TCP连接请求
- public static boolean connect_request_flag = false;
- //session
- public static String sessionid = "";
- public static JPanel contentPane;
- public static MesClient mesClientFrame;
- public static JTabbedPane tabbedPane;
- public static JScrollPane indexScrollPaneA;
- public static JScrollPane searchScrollPane;
- public static JScrollPane searchScrollPaneD;
- public static JScrollPane searchScrollPaneDj;
- public static JScrollPane searchScrollPaneTask;
- public static Boolean check_quality_result = false;
- public static Integer work_status = 0;
- public static JButton heart_beat_menu;
- public static JButton status_menu;
- public static JButton user_menu;
- public static int scan_type = 0;
- public static JButton finish_ok_bt;
- public static JButton finish_ng_bt;
- public static JTextField product_sn;
- public static JButton f_scan_data_bt_1;
- //新增字段
- public static ProductTypePanel productTypePanel;
- public static JLabel productTypeCurrentLabel;
- public static final int PRODUCT_SN_LENGTH = 32;
- public static final String PREFIX_ZJ = "000020021815-01000016"; //智界
- public static final String PREFIX_SJ = "000020022029-01000016"; //尚界
- public static final String PRODUCT_TYPE_SWITCH_PASSWORD = "503833";
- public static final String PRODUCT_TYPE_ZJ = ProductTypePanel.TYPE_ZJ;
- public static final String PRODUCT_TYPE_SJ = ProductTypePanel.TYPE_SJ;
- public static String user20 = "";
- public static boolean mes_enable = true; // true=MES开启
- public static JFrame welcomeWin;
- public static JPanel indexPanelB;
- public static MesWebView jfxPanel = null;
- public static JPanel indexPanelC;
- public static JPanel indexPanelD;
- public static MesWebView jfxPanel2 = null;
- public static MesWebView jfxPanel3 = null;
- public static MesRadio mesRadioHj;
- public static JLabel curTaskName;
- public static JTable table;
- public static Object[] columnNames = {"工件码", "测试日期", "压力", "泄露值","结果"};
- // public static Object[][] rowData = null;
- // public static Object[][] rowData = {
- // {"151245P00001213100100024120700111","2024-12-09 12:30:30","60","60","60","200kPa","3ml/min","OK"},
- // {"151245P00001213100100024120700112","2024-12-09 13:30:30","60","60","60","-200kPa","3ml/min","OK"},
- // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"},
- // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"},
- // };
- public static Object[][] rowData = new Object[12][5];
- public static JLabel pageLabel;
- public static int pageNo=1 ; // 当前页
- public static int totalPages; // 总页数
- public static JTextField textField;//搜索框
- public static JTable table2;
- public static Object[] columnNames2 = { "任务名称" };
- public static Object[][] rowData2 = {{""},{""},{""}};
- public static JTable materialTable;
- public static Object[] materialColumnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
- public static Object[][] materialRowData = null;
- public static Integer tjFlag = 0;
- public static String tjFlagText2 = "设备运行中";
- public static String tjFlagText3 = "设备运行结束";
- public static String tjFlagText4 = "结果已上传MES,请扫下一件";
- public static String tjFlagText5 = "已扫码,等待设备运行";
- public static String tjFlagTextErr = "结果上传MES失败,请重试";
- public static SerialPortUtils serialPortUtils;
- public static JTextField printSn2;
- public static JTextField printTitle2;
- public static JTextField printValue2;
- public static JButton printBtn2;
- public static ConfigParam configParam;
- public static Integer isConfigEdit = 0;
- public static Integer mesStartFlag = 0;
- /** MES开启时,仪器判NG后暂存,待工人填写漏点点位再上传 */
- public static TestParam pendingNgTestParam = null;
- public static List<TaskParam> taskParamList = new ArrayList<>();
- public static TaskParam curTaskParam = null;
- public static void main(String[] args) {
- if (ClientUpgrade.handleInstallArgs(args)) {
- return;
- }
- if (LockUtil.getInstance().isAppActive() == true){
- // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
- return;
- }
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- try{
- //读文件配置
- readProperty();
- if (ClientUpgrade.recoverIncompleteInstall()) {
- return;
- }
- ClientUpgrade.cleanupInstallLeftovers();
- ClientUpgrade.checkIfConfigured(null);
- // 显示界面
- mesClientFrame = new MesClient();
- mesClientFrame.setVisible(false);
- JdbcUtils.getConn();
- welcomeWin = new LoginFarme();
- welcomeWin.setVisible(true);
- formatConfigEdit(false);
- formatConfigData();
- getTask();
- serialPortUtils=new SerialPortUtils(configParam.getSerialPort(),getEffectiveOprno(),configParam.getOprnoTitle(),configParam.getDevice());
- // startDateTimer();
- textFocus();
- // resetScanA();
- }catch (Exception e){
- log.error(e.getMessage());
- }
- }
- });
- }
- public static Timer cjTimerText;
- public static void textFocus() {
- if(cjTimerText!=null) {
- cjTimerText.cancel();
- }
- cjTimerText = new Timer();
- cjTimerText.schedule(new TimerTask() {
- public void run() {
- if(work_status == 0){
- product_sn.requestFocusInWindow();
- }
- }
- }, 1000,1000);
- }
- public static java.util.Timer dateBeatTimer;
- public static void startDateTimer() {
- if (dateBeatTimer != null) {
- dateBeatTimer.cancel();
- }
- dateBeatTimer = new java.util.Timer();
- dateBeatTimer.schedule(new TimerTask() {
- public void run() {
- if (iconREDFlag) {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- iconREDFlag = false;
- } else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
- iconREDFlag = true;
- }
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- heart_beat_menu.setForeground(Color.GREEN);
- heart_beat_menu.repaint();
- }
- }, 100, 1* 1000);
- }
- //读配置文件
- private static String parseClientVersion(String value) {
- if (value == null || value.trim().isEmpty()) {
- return "0.0.0";
- }
- return ClientVersionUtils.normalize(value.trim());
- }
- private static void readProperty() throws IOException{
- String enconding = "UTF-8";
- InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
- Properties pro = new Properties();
- BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
- pro.load(br);
- client_version = parseClientVersion(pro.getProperty("mes.client.version"));
- mes_server_ip = pro.getProperty("mes.server_ip");
- mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
- mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
- String gw = pro.getProperty("mes.gw");
- if (gw != null && !gw.trim().isEmpty()) {
- mes_gw = gw.trim();
- }
- String lineSn = pro.getProperty("mes.line_sn");
- if (lineSn != null && !lineSn.trim().isEmpty()) {
- mes_line_sn = lineSn.trim();
- }
- mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
- log.info(mes_gw + ";" + mes_line_sn + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
- }
- // 初始化TCP
- public static void initTcpConnection() {
- try {
- if(nettyClient==null) {
- //初始化TCP连接
- nettyClient = new NettyClient();
- //TCP连接状态
- tcp_connect_flag = false;
- //设置TCP请求状态
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient);
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //启动心跳包程序
- public static java.util.Timer heartBeatTimer;
- public static java.util.Timer heartBeatIconTimer;
- public static boolean iconREDFlag = true;
- public static void startHeartBeatTimer() {
- if(heartBeatTimer!=null) {
- heartBeatTimer.cancel();
- }
- heartBeatTimer = new java.util.Timer();
- heartBeatTimer.schedule(new TimerTask() {
- public void run() {
- if(nettyClient!=null&&tcp_connect_flag) {
- //log.info("发送心跳报文");
- DataUtil.heartBeat(nettyClient);
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- }
- }
- }, 100,mes_heart_beat_cycle*1000);
- //心跳显示图标
- if(heartBeatIconTimer!=null) {
- heartBeatIconTimer.cancel();
- }
- heartBeatIconTimer = new Timer();
- heartBeatIconTimer.schedule(new TimerTask() {
- public void run() {
- if(tcp_connect_flag) {
- if(iconREDFlag) {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- iconREDFlag = false;
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
- iconREDFlag = true;
- }
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- heart_beat_menu.repaint();
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
- heart_beat_menu.repaint();
- //若未连接则尝试连接
- if(nettyClient!=null&&!tcp_connect_flag){
- log.info("TCP已断开");
- //TCP重新同步连接
- if(!connect_request_flag) {
- //log.info("TCP重新同步连接");
- //设置TCP请求状态,只重新同步连接一次
- connect_request_flag = true;
- DataUtil.synrTcp(nettyClient);
- }
- }
- }
- }
- }, 100,mes_heart_icon_cycle*1000);
- }
- //设置tcp连接状态显示
- public static void setTcpStatus() {
- if(tcp_connect_flag) {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }else {
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
- heart_beat_menu.repaint();
- }
- }
- public static void initWarehouseData(){
- loadProductTypeFromDb(); //新增
- resetScanA();
- }
- public static void resetScanA() {
- work_status = 0;
- check_quality_result = false;
- pendingNgTestParam = null;
- MesClient.finish_ok_bt.setEnabled(false);
- MesClient.finish_ng_bt.setEnabled(false);
- MesClient.finish_ng_bt.setVisible(false);
- product_sn.setText("");
- product_sn.setEditable(true);
- tjFlag = 0;
- mesStartFlag = 0;
- curTaskName.setText("");
- // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
- // f_scan_data_bt_1.setText("扫码");
- // MesClient.f_scan_data_bt_1.setEnabled(true);
- MesClient.setMenuStatus("请扫工件码",0);
- updateMaterailData();
- if (MesClient.result != null) {
- MesClient.result.setText("");
- MesClient.result.setVisible(false);
- }
- }
- /**
- * 本地存库后提交MES,成功则复位扫码。
- * NG 且未填漏点(MES开启)时暂存并点亮 NG 按钮,不入库不上传。
- */
- public static boolean afterTestSaveAndUpload(TestParam testParam) {
- try {
- String testDate = testParam.getCreateTime();
- if (testDate == null || testDate.isEmpty()) {
- testDate = DateLocalUtils.getCurrentTime();
- testParam.setCreateTime(testDate);
- }
- if (testParam.getOprno() == null || testParam.getOprno().isEmpty()) {
- testParam.setOprno(getEffectiveOprno());
- }
- if (testParam.getLineSn() == null || testParam.getLineSn().isEmpty()) {
- testParam.setLineSn(getEffectiveLineSn());
- }
- boolean isNg = testParam.getResult() != null && testParam.getResult().equalsIgnoreCase("NG");
- boolean leakEmpty = testParam.getNgLeakPoints() == null || testParam.getNgLeakPoints().trim().isEmpty();
- if (mes_enable && isNg && leakEmpty) {
- pendingNgTestParam = testParam;
- MesClient.finish_ng_bt.setVisible(true);
- MesClient.finish_ng_bt.setEnabled(true);
- MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
- if (SwingUtilities.isEventDispatchThread()) {
- submitPendingNgWithLeakPoints();
- } else {
- SwingUtilities.invokeLater(MesClient::submitPendingNgWithLeakPoints);
- }
- return false;
- }
- JdbcUtils.insertTestRecord(testParam);
- if (mes_enable) {
- JSONObject retObj = DataUtil.qmResultData(testParam);
- if (retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
- pendingNgTestParam = null;
- MesClient.resetScanA();
- MesClient.setMenuStatus("测试结果上传成功,请扫下一件", 0);
- try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
- if (MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())) {
- PrintUtil.printLabel(testParam.getSn(),
- (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
- (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
- testDate);
- }
- return true;
- } else {
- MesClient.mesStartFlag = 0;
- MesClient.setMenuStatus("测试结果上传失败,请重试", -1);
- return false;
- }
- } else {
- pendingNgTestParam = null;
- MesClient.resetScanA();
- try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
- if (MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())) {
- PrintUtil.printLabel(testParam.getSn(),
- (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
- (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
- testDate);
- }
- return true;
- }
- } catch (Exception e) {
- log.error("保存上传测试结果失败", e);
- MesClient.setMenuStatus("测试结果保存失败,请重试", -1);
- return false;
- }
- }
- /** 工人点击 NG 后:打开漏点页并上传 */
- public static void submitPendingNgWithLeakPoints() {
- if (pendingNgTestParam == null) {
- MesClient.setMenuStatus("无待填写的气密NG数据", -1);
- return;
- }
- String ngLeakPoints = LeakNgPointDialog.showDialog(mesClientFrame);
- if (ngLeakPoints == null) {
- MesClient.finish_ng_bt.setVisible(true);
- MesClient.finish_ng_bt.setEnabled(true);
- MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
- return;
- }
- pendingNgTestParam.setNgLeakPoints(ngLeakPoints);
- afterTestSaveAndUpload(pendingNgTestParam);
- }
- public static int userLoginHours;//用户登录所处小时
- public static JTextField param1;
- public static JTextField param2;
- public static JTextField param3;
- public static JTextField param4;
- public static JLabel result;
- public static JTextField programNo;
- public static JTextField serialPort;
- public static JTextField baudRate;
- public static JTextField printName;
- public static JTextField labelName;
- public static JTextField labelx;
- public static JTextField labely;
- public static JTextField labelLineSpace;
- public static JTextField labelFont;
- public static JTextField stationNo;
- public static JComboBox stopBit;
- public static JComboBox checkBit;
- public static JComboBox dataBits;
- public static JComboBox printLabel;
- public static JComboBox leakage;
- public static JComboBox startMode;
- public static JButton saveBtn;
- public static JTextField productSnLength;
- public static JTextField productSnPre;
- public static JComboBox device;
- public static JTextField ngTime;
- public static JTextField ngNumber;
- public static JTextField ngUpgradeTime;
- public static JTextField oprno;
- public static JTextField oprnoTitle;
- public static JTextField lineSn;
- public static JLabel taskName;
- public static JTextField taskMaxNumA;
- public static JTextField taskMaxFoutA;
- public static JTextField taskMinFoutA;
- public static JTextField taskMaxSoutA;
- public static JTextField taskMinSoutA;
- public static JTextField taskMaxNumB;
- public static JTextField taskMaxFoutB;
- public static JTextField taskMinFoutB;
- public static JTextField taskMaxSoutB;
- public static JTextField taskMinSoutB;
- public static JComboBox taskLeakage;
- public static JTextField barcodeSpec;
- public static JTextField barcodeSpecStart;
- public static JTextField barcodeLength;
- public static void formatConfigEdit(Boolean ret){
- programNo.setEnabled(ret);
- serialPort.setEnabled(ret);
- startMode.setEnabled(ret);
- baudRate.setEnabled(ret);
- printName.setEnabled(ret);
- labelName.setEnabled(ret);
- labelx.setEnabled(ret);
- labely.setEnabled(ret);
- labelLineSpace.setEnabled(ret);
- labelFont.setEnabled(ret);
- stationNo.setEnabled(ret);
- stopBit.setEnabled(ret);
- checkBit.setEnabled(ret);
- dataBits.setEnabled(ret);
- printLabel.setEnabled(ret);
- leakage.setEnabled(ret);
- productSnPre.setEnabled(ret);
- productSnLength.setEnabled(ret);
- device.setEnabled(ret);
- // ngTime.setEnabled(ret);
- // ngNumber.setEnabled(ret);
- // ngUpgradeTime.setEnabled(ret);
- oprno.setEnabled(ret);
- oprnoTitle.setEnabled(ret);
- lineSn.setEnabled(ret);
- }
- public static void formatConfigData(){
- MesClient.configParam = JdbcUtils.getConfig();
- log.info(configParam.toString());
- if(configParam.getProgramNo() == null||configParam.getProgramNo().isEmpty()){
- configParam.setProgramNo("1");
- }
- programNo.setText(configParam.getProgramNo());
- if(configParam.getStartMode() == null||configParam.getStartMode().isEmpty()){
- configParam.setStartMode("手动启动");
- }
- startMode.setSelectedItem(configParam.getStartMode());
- if(configParam.getSerialPort() == null||configParam.getSerialPort().isEmpty()){
- configParam.setSerialPort("COM1");
- }
- serialPort.setText(configParam.getSerialPort());
- if(configParam.getBaudRate() == null||configParam.getBaudRate().isEmpty()){
- configParam.setBaudRate("38400");
- }
- baudRate.setText(configParam.getBaudRate());
- if(configParam.getDataBits() == null||configParam.getDataBits().isEmpty()){
- configParam.setDataBits("8");
- }
- dataBits.setSelectedItem(configParam.getDataBits());
- if(configParam.getCheckBit() == null||configParam.getCheckBit().isEmpty()){
- configParam.setCheckBit("NONE");
- }
- checkBit.setSelectedItem(configParam.getCheckBit());
- if(configParam.getStopBit() == null||configParam.getStopBit().isEmpty()){
- configParam.setStopBit("1");
- }
- stopBit.setSelectedItem(configParam.getStopBit());
- if(configParam.getLeakage() == null||configParam.getLeakage().isEmpty()){
- configParam.setLeakage("压降");
- }
- leakage.setSelectedItem(configParam.getLeakage());
- if(configParam.getPrintLabel() == null||configParam.getPrintLabel().isEmpty()){
- configParam.setPrintLabel("否");
- }
- printLabel.setSelectedItem(configParam.getPrintLabel());
- if(configParam.getPrintName() == null||configParam.getPrintName().isEmpty()){
- configParam.setPrintName("");
- }
- printName.setText(configParam.getPrintName());
- if(configParam.getLabelName() == null||configParam.getLabelName().isEmpty()){
- configParam.setLabelName("");
- }
- labelName.setText(configParam.getLabelName());
- if(configParam.getLabelx() == null||configParam.getLabelx().isEmpty()){
- configParam.setLabelx("30");
- }
- labelx.setText(configParam.getLabelx());
- if(configParam.getLabely() == null||configParam.getLabely().isEmpty()){
- configParam.setLabely("30");
- }
- labely.setText(configParam.getLabely());
- if(configParam.getLabelLineSpace() == null||configParam.getLabelLineSpace().isEmpty()){
- configParam.setLabelLineSpace("20");
- }
- labelLineSpace.setText(configParam.getLabelLineSpace());
- if(configParam.getLabelFont() == null||configParam.getLabelFont().isEmpty()){
- configParam.setLabelFont("10");
- }
- labelFont.setText(configParam.getLabelFont());
- if(configParam.getStationNo() == null||configParam.getStationNo().isEmpty()){
- configParam.setStationNo("1");
- }
- stationNo.setText(configParam.getStationNo());
- if(configParam.getProductSnPre() == null||configParam.getProductSnPre().isEmpty()){
- configParam.setProductSnPre("");
- }
- productSnPre.setText(configParam.getProductSnPre());
- if(configParam.getProductSnLength() == null||configParam.getProductSnLength().isEmpty()){
- configParam.setProductSnLength("");
- }
- productSnLength.setText(configParam.getProductSnLength());
- if(configParam.getDevice() == null||configParam.getDevice().isEmpty()){
- configParam.setDevice("innomatec");
- }
- device.setSelectedItem(configParam.getDevice());
- // if(configParam.getNgTime() == null||configParam.getNgTime().isEmpty()){
- // configParam.setNgTime("");
- // }
- // ngTime.setText(configParam.getNgTime());
- //
- // if(configParam.getNgNumber() == null||configParam.getNgNumber().isEmpty()){
- // configParam.setNgNumber("");
- // }
- // ngNumber.setText(configParam.getNgNumber());
- //
- // if(configParam.getNgUpgradeTime() == null||configParam.getNgUpgradeTime().isEmpty()){
- // configParam.setNgUpgradeTime("");
- // }
- // ngUpgradeTime.setText(configParam.getNgUpgradeTime());
- if(configParam.getOprno() == null||configParam.getOprno().isEmpty()){
- configParam.setOprno(mes_gw != null ? mes_gw : "");
- }
- oprno.setText(configParam.getOprno());
- if(configParam.getOprnoTitle() == null||configParam.getOprnoTitle().isEmpty()){
- configParam.setOprnoTitle("");
- }
- oprnoTitle.setText(configParam.getOprnoTitle());
- if(configParam.getLineSn() == null||configParam.getLineSn().isEmpty()){
- configParam.setLineSn(mes_line_sn != null && !mes_line_sn.isEmpty() ? mes_line_sn : "XT");
- }
- lineSn.setText(configParam.getLineSn());
- if(!oprnoTitle.getText().isEmpty()){
- String stationInfo = oprno.getText() +"-"+ oprnoTitle.getText();
- welcomeWin.setTitle("气密检测客户端--"+stationInfo);
- mesClientFrame.setTitle("气密检测客户端--"+stationInfo);
- }
- syncStationFromConfig();
- }
- private static void syncStationFromConfig() {
- if (configParam == null) {
- return;
- }
- if (configParam.getOprno() != null) {
- mes_gw = configParam.getOprno();
- }
- if (configParam.getLineSn() != null && !configParam.getLineSn().isEmpty()) {
- mes_line_sn = configParam.getLineSn();
- }
- mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
- }
- public static String getEffectiveOprno() {
- if (configParam != null) {
- String oprno = configParam.getOprno();
- if (oprno != null && !oprno.trim().isEmpty()) {
- return oprno.trim();
- }
- }
- if (mes_gw != null && !mes_gw.trim().isEmpty()) {
- return mes_gw.trim();
- }
- return "";
- }
- public static String getEffectiveLineSn() {
- if (configParam != null) {
- String lineSn = configParam.getLineSn();
- if (lineSn != null && !lineSn.trim().isEmpty()) {
- return lineSn.trim();
- }
- }
- if (mes_line_sn != null && !mes_line_sn.trim().isEmpty()) {
- return mes_line_sn.trim();
- }
- return "XT";
- }
- //换班用户信息检查
- private static void shiftUserCheck() {
- LocalDateTime now = LocalDateTime.now();
- // 判断时间范围
- if (userLoginHours >= 8 && userLoginHours < 20) {
- int hour = now.getHour();
- if (hour >= 20 || hour < 8) {
- logoff();
- }
- } else {
- int hour = now.getHour();
- if (hour >= 8 && hour < 20) {
- logoff();
- }
- }
- }
- public static void resetScanB() {
- }
- //获取用户20位
- public static void getUser() {
- user20 = user_menu.getText().toString();
- String space_tmp1 = "";
- if(user20.length()<20) {
- for(int i=0;i<20-user20.length();i++) {
- space_tmp1 = space_tmp1 + " ";
- }
- }
- user20 = user20 + space_tmp1;
- }
- //获取barcode内容36位
- public static String getBarcode(String barcodeTmp) {
- String barcodeRet = barcodeTmp;
- if(barcodeTmp.equalsIgnoreCase("")) {
- return "";
- }else {
- if(barcodeTmp.length()<36) {
- String space = "";
- for(int i=0;i<36-barcodeTmp.length();i++) {
- space = space + " ";
- }
- barcodeRet = barcodeTmp + space;
- }
- }
- return barcodeRet;
- }
- public static void scanBarcode() {
- if (work_status == 1) {
- MesClient.serialPortUtils.start();
- return;
- }
- }
- public static void scanBarcode2() {
- if(work_status == 1){
- // MesClient.serialPortUtils.sendData("START");
- return;
- }
- String scanBarcode = product_sn.getText().trim();
- //刷新界面
- mesClientFrame.repaint();
- //生产类型新增
- String validateMsg = validateProductSnMessage(scanBarcode);
- if (validateMsg != null) {
- check_quality_result = false;
- work_status = 0;
- MesClient.finish_ok_bt.setEnabled(false);
- MesClient.finish_ng_bt.setEnabled(false);
- MesClient.f_scan_data_bt_1.setEnabled(true);
- updateProductTypePanelEnabled(true);
- MesClient.setMenuStatus(validateMsg, -1);
- return;
- }
- updateProductTypePanelEnabled(false);
- if(scanBarcode.isEmpty()){
- MesClient.setMenuStatus("工件码不能为空",1);
- product_sn.setText("");
- return;
- }
- // // 验证工件码前缀
- // if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
- // int preLen = MesClient.configParam.getProductSnPre().trim().length();
- // if(preLen > scanBarcode.length()){
- // MesClient.setMenuStatus("工件码前缀不符合要求",-1);
- // product_sn.setText("");
- // return;
- // }else{
- // String pre = scanBarcode.substring(0,preLen);
- // if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
- // MesClient.setMenuStatus("工件码前缀不符合要求",-1);
- // product_sn.setText("");
- // return;
- // }
- // }
- // }
- //
- // //验证工件码长度
- // int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
- // if(snLen > 0 && snLen != scanBarcode.length()) {
- // MesClient.setMenuStatus("工件码长度不符合要求",-1);
- // product_sn.setText("");
- // return;
- // }
- // // 验证NG
- // int isCheck = JdbcUtils.checkSnTimer(scanBarcode,configParam);
- // System.err.println("isCheck:" + isCheck);
- // if(isCheck == 1){
- // int ngTime = Integer.valueOf(configParam.getNgTime());
- // MesClient.setMenuStatus("工件码测试NG必须间隔"+ngTime+"分钟",-1);
- // product_sn.setText("");
- // return;
- // } else if(isCheck == 2){
- // int ngUpgradeTime = Integer.valueOf(configParam.getNgUpgradeTime());
- // int ngNumber = Integer.valueOf(configParam.getNgNumber());
- // MesClient.setMenuStatus("工件码测试NG"+ngNumber+"次,必须间隔"+ngUpgradeTime+"分钟",-1);
- // product_sn.setText("");
- // return;
- // }
- if(checkProductSn(scanBarcode.trim())){
- serialPortUtils.changeProgram(); // 切换程序
- if(MesClient.mes_enable){
- getUser();
- // 查询工件质量
- Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcode,user20);
- if(!sendret){
- MesClient.setMenuStatus("消息发送失败,请重试",-1);
- return;
- }
- }else{
- work_status = 1;
- MesClient.tjFlag = 1;
- MesClient.setMenuStatus("扫码成功,等待测试",0);
- product_sn.setEditable(false);
- if(MesClient.configParam.getStartMode().equals("自动启动")){
- MesClient.serialPortUtils.start();
- }
- MesClient.result.setVisible(true);
- MesClient.result.setText("等待结果");
- MesClient.result.setForeground(Color.GRAY);
- }
- }
- // f_scan_data_bt_1.setIcon(null);
- // f_scan_data_bt_1.setText("启动");
- }
- public static void scanBarcodeOld() {
- if(work_status == 1){
- // MesClient.serialPortUtils.sendData("START");
- return;
- }
- String scanBarcodeTitle = "";
- switch(scan_type) {
- case 1:
- product_sn.setText("");
- scanBarcodeTitle = "请扫工件码";
- break;
- }
- //弹窗扫工件码
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
- // 验证工件码前缀
- if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
- int preLen = MesClient.configParam.getProductSnPre().trim().length();
- if(preLen > scanBarcode.length()){
- MesClient.setMenuStatus("工件码前缀不符合要求",-1);
- return;
- }else{
- String pre = scanBarcode.substring(0,preLen);
- if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
- MesClient.setMenuStatus("工件码前缀不符合要求",-1);
- return;
- }
- }
- }
- //验证工件码长度
- int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
- if(snLen > 0 && snLen != scanBarcode.length()) {
- MesClient.setMenuStatus("工件码长度不符合要求",-1);
- return;
- }
- //获取用户
- getUser();
- //获取扫码内容36位
- String barcode36 = getBarcode(scanBarcode);//处理36为码
- //工位号
- String gw = "";
- switch(scan_type) {
- case 1:
- product_sn.setText(scanBarcode);
- break;
- }
- //刷新界面
- mesClientFrame.repaint();
- work_status = 1;
- // f_scan_data_bt_1.setEnabled(false);
- MesClient.tjFlag = 1;
- MesClient.setMenuStatus("扫码成功,等待测试",0);
- if(MesClient.configParam.getStartMode().equals("自动启动")){
- MesClient.serialPortUtils.start();
- }
- f_scan_data_bt_1.setIcon(null);
- f_scan_data_bt_1.setText("启动");
- }else {
- JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- }
- public static void logoff() {
- // welcomeWin.setVisible(true);
- mesClientFrame.setVisible(false);
- //退出程序 退出登录
- System.exit(0);
- nettyClient = null;
- // if(heartBeatTimer!=null) {
- // heartBeatTimer.cancel();
- // }
- // if(heartBeatIconTimer!=null) {
- // heartBeatIconTimer.cancel();
- // }
- tcp_connect_flag = false;
- connect_request_flag = false;
- }
- public MesClient() {
- setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
- setTitle("气密检测客户端");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(0, 0, 1024, 768);
- JMenuBar menuBar = new JMenuBar();
- menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
- setJMenuBar(menuBar);
- JMenu fileMenu = new JMenu("用户");
- fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
- fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- menuBar.add(fileMenu);
- JMenuItem exitMenuItem = new JMenuItem("退出");
- exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
- exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
- fileMenu.add(exitMenuItem);
- exitMenuItem.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
- super.mouseClicked(e);
- //dispose();
- logoff();
- }
- });
- JMenu settingMenu = new JMenu("设置");
- //settingMenu.setVisible(false);
- settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
- settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- menuBar.add(settingMenu);
- JMenuItem resetTcpMenu = new JMenuItem("重连MES");
- resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetTcpMenu.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- //重连mes
- nettyClient.future.channel().close();
- }
- });
- // settingMenu.add(resetTcpMenu);
- JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
- resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
- resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetTcpMenu_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- super.mouseClicked(e);
- resetScanA();
- }
- });
- settingMenu.add(resetTcpMenu_1);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(new BorderLayout(0, 0));
- JToolBar toolBar = new JToolBar();
- contentPane.add(toolBar, BorderLayout.NORTH);
- JLabel equipment_statu_label = new JLabel("状态:");
- equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
- equipment_statu_label.setForeground(Color.BLACK);
- equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- equipment_statu_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(equipment_statu_label);
- status_menu = new JButton("设备未连接MES服务器");
- if(tcp_connect_flag) {
- MesClient.setMenuStatus("已连接MES服务器",0);
- status_menu.setForeground(Color.GREEN);
- }else {
- MesClient.setMenuStatus("请扫工件码",-1);
- status_menu.setForeground(Color.DARK_GRAY);
- }
- status_menu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- status_menu.setForeground(Color.GREEN);
- status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- status_menu.setBackground(Color.BLACK);
- toolBar.add(status_menu);
- JLabel space_1 = new JLabel(" ");
- toolBar.add(space_1);
- JLabel heart_beat_status_label = new JLabel("心跳:");
- heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- heart_beat_status_label.setForeground(Color.BLACK);
- heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(heart_beat_status_label);
- heart_beat_menu = new JButton("");
- heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
- heart_beat_menu.setForeground(Color.GREEN);
- heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- heart_beat_menu.setBackground(Color.BLACK);
- toolBar.add(heart_beat_menu);
- JLabel space_2 = new JLabel(" ");
- toolBar.add(space_2);
- JLabel user_status_label = new JLabel("登录用户:");
- user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
- user_status_label.setForeground(Color.BLACK);
- user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- user_status_label.setBackground(Color.LIGHT_GRAY);
- toolBar.add(user_status_label);
- user_menu = new JButton("");
- user_menu.setForeground(Color.GREEN);
- user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
- user_menu.setBackground(Color.BLACK);
- toolBar.add(user_menu);
- JLabel space_3 = new JLabel(" ");
- toolBar.add(space_3);
- JLabel space_4 = new JLabel(" ");
- toolBar.add(space_4);
- tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
- tabbedPane.setMinimumSize(new Dimension(400, 50));
- tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
- contentPane.add(tabbedPane);
- //首页
- JPanel indexPanelA = new JPanel();
- indexScrollPaneA = new JScrollPane(indexPanelA);
- indexPanelA.setLayout(null);
- curTaskName = new JLabel("当前任务:");
- curTaskName.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- curTaskName.setHorizontalAlignment(SwingConstants.CENTER);
- curTaskName.setBounds(81, 10, 800, 40);
- indexPanelA.add(curTaskName);
- product_sn = new JTextField();
- product_sn.setHorizontalAlignment(SwingConstants.LEFT);
- product_sn.setEditable(true);
- product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
- product_sn.setBounds(81, 70, 602, 70);
- indexPanelA.add(product_sn);
- product_sn.setColumns(10);
- product_sn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scan_type = 1;
- scanBarcode2();
- }
- });
- // f_scan_data_bt_1 = new JButton("扫码");
- f_scan_data_bt_1 = new JButton("启动");
- f_scan_data_bt_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- scan_type = 1;
- scanBarcode();
- }
- });
- // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
- f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- f_scan_data_bt_1.setBounds(693, 70, 198, 70);
- indexPanelA.add(f_scan_data_bt_1);
- JLabel lblNewLabel = new JLabel("测试压");
- lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel.setBounds(137, 210, 140, 40);
- indexPanelA.add(lblNewLabel);
- param1 = new JTextField();
- param1.setEditable(false);
- param1.setBounds(287, 210, 150, 40);
- indexPanelA.add(param1);
- param1.setColumns(10);
- JLabel lblNewLabel_1 = new JLabel("泄露值");
- lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- lblNewLabel_1.setBounds(447, 210, 140, 40);
- indexPanelA.add(lblNewLabel_1);
- param2 = new JTextField();
- param2.setEditable(false);
- param2.setColumns(10);
- param2.setBounds(597, 210, 150, 40);
- indexPanelA.add(param2);
- JLabel lblNewLabel_2 = new JLabel("测电阻电压");
- lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- lblNewLabel_2.setBounds(137, 288, 140, 40);
- // indexPanelA.add(lblNewLabel_2);
- param3 = new JTextField();
- param3.setEditable(false);
- param3.setColumns(10);
- param3.setBounds(287, 288, 150, 40);
- // indexPanelA.add(param3);
- JLabel lblNewLabel_1_1 = new JLabel("电阻");
- lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- lblNewLabel_1_1.setBounds(447, 288, 140, 40);
- // indexPanelA.add(lblNewLabel_1_1);
- param4 = new JTextField();
- param4.setEditable(false);
- param4.setColumns(10);
- param4.setBounds(597, 288, 150, 40);
- // indexPanelA.add(param4);
- result = new JLabel("等待结果") {
- @Override
- protected void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- // 设置圆角背景和边框颜色
- g2.setColor(new Color(255, 255, 255)); // 背景颜色
- g2.fillRoundRect(0, 0, getWidth(), getHeight(), 20, 20); // 圆角矩形,圆角半径为20
- g2.setColor(new Color(255, 255, 255)); // 边框颜色
- g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 20, 20); // 绘制边框
- g2.dispose();
- super.paintComponent(g);
- }
- };
- // result.setForeground(Color.GREEN);
- // result.setForeground(Color.RED);
- result.setForeground(Color.GRAY);
- result.setHorizontalAlignment(SwingConstants.CENTER);
- result.setFont(new Font("微软雅黑", Font.BOLD, 50));
- // result.setBounds(290, 392, 356, 89);
- result.setBounds(290, 332, 356, 89);
- result.setVisible(false);
- indexPanelA.add(result);
- finish_ok_bt = new JButton("OK");
- finish_ok_bt.setEnabled(false);
- finish_ok_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String sn = getBarcode(product_sn.getText());
- if(sn.isEmpty()){
- MesClient.setMenuStatus("工件码为空,请重试",-1);
- return;
- }
- //生产类型新增
- String validateMsg = validateProductSnMessage(sn);
- if (validateMsg != null) {
- MesClient.setMenuStatus(validateMsg, -1);
- return;
- }
- }
- });
- finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
- finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- finish_ok_bt.setBounds(185, 291, 240, 80);
- finish_ok_bt.setEnabled(false);
- // indexPanelA.add(finish_ok_bt);
- finish_ng_bt = new JButton("NG");
- finish_ng_bt.setEnabled(false);
- finish_ng_bt.setVisible(false);
- finish_ng_bt.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- submitPendingNgWithLeakPoints();
- }
- });
- finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
- finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
- finish_ng_bt.setBounds(508, 291, 240, 80);
- finish_ng_bt.setEnabled(false);
- indexPanelA.add(finish_ng_bt);
- tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
- tabbedPane.setEnabledAt(0, true);
- indexPanelC = new JPanel();
- searchScrollPaneDj = new JScrollPane(indexPanelC);
- // indexPanelC.setLayout(new GridLayout(0, 1, 0, 0));
- indexPanelC.setLayout(null);
- JPanel panel2 = new JPanel();
- panel2.setBounds(0, 0, 990, 50);
- // panel2.setLayout(new GridLayout(0, 1, 0, 0));
- panel2.setLayout(null);
- //记录查询搜索框
- textField = new JTextField();
- textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // textField.setEnabled(false);
- textField.setForeground(Color.BLACK);
- textField.setBounds(10, 5, 371, 40);
- panel2.add(textField);
- // textField.setColumns(20);
- indexPanelC.add(panel2);
- JButton btnNewButton = new JButton("搜索");
- btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- btnNewButton.setBounds(385, 5, 90, 40);
- panel2.add(btnNewButton);
- // 上一页按钮添加按钮事件监听
- btnNewButton.addActionListener(e -> {
- JdbcUtils.getTestData();
- });
- JButton resetBtn = new JButton("重置");
- resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetBtn.setBounds(475, 5, 90, 40);
- panel2.add(resetBtn);
- // 上一页按钮添加按钮事件监听
- resetBtn.addActionListener(e -> {
- textField.setText("");
- JdbcUtils.getTestData();
- });
- JButton resetBtn2 = new JButton("导出");
- resetBtn2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- resetBtn2.setBounds(565, 5, 90, 40);
- panel2.add(resetBtn2);
- // 上一页按钮添加按钮事件监听
- resetBtn2.addActionListener(e -> {
- List<QmData> lists = JdbcUtils.getTestDataAll();
- Boolean ret = ExportUtil.export(lists);
- if(ret){
- MesClient.setMenuStatus("导出成功,请在D盘中查看",0);
- }else{
- MesClient.setMenuStatus("导出失败,请重试",-1);
- }
- });
- JButton btnPrevious = new JButton("上一页");
- btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
- btnPrevious.setBounds(680, 5, 100, 40);
- panel2.add(btnPrevious);
- // 页码显示
- pageLabel = new JLabel("0/0"); // 初始页码和总页数
- pageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
- pageLabel.setHorizontalAlignment(SwingConstants.CENTER); // 设置文本居中对齐
- pageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); // 添加灰色边框
- pageLabel.setBounds(780, 5, 100, 40); // 设置位置和大小
- panel2.add(pageLabel);
- // “下一页”按钮
- JButton btnNext = new JButton("下一页");
- btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
- btnNext.setBounds(880, 5, 100, 40);
- panel2.add(btnNext);
- // 分页逻辑变量
- // 上一页按钮添加按钮事件监听
- btnPrevious.addActionListener(e -> {
- if (pageNo > 1) {
- pageNo--;
- JdbcUtils.getTestData();
- }
- });
- btnNext.addActionListener(e -> {
- if (pageNo < totalPages) {
- pageNo++;
- JdbcUtils.getTestData();
- }
- });
- JPanel panel = new JPanel();
- panel.setBounds(0, 49, 990, 518);
- panel.setLayout(new GridLayout(0, 1, 0, 0));
- indexPanelC.add(panel);
- System.err.println(JSONObject.toJSONString(rowData));
- System.err.println(columnNames.length);
- table = new JTable(rowData, columnNames) {
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- // 添加 MouseListener 获取点击事件
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- if(e.getClickCount() == 1) {
- int row = table.rowAtPoint(e.getPoint()); // 获取点击的行号
- int col = table.columnAtPoint(e.getPoint()); // 获取点击的列号
- if (row >= 0 && col >= 0) { // 确保点击在数据区域内
- Object value = table.getValueAt(row, col); // 获取点击单元格的数据
- System.out.println("Clicked cell value: " + value);
- // 获取整行的数据
- Object[] rowData = new Object[table.getColumnCount()];
- for (int i = 0; i < table.getColumnCount(); i++) {
- rowData[i] = table.getValueAt(row, i);
- }
- log.info("Row data: " + java.util.Arrays.toString(rowData));
- log.info("O:"+String.valueOf(rowData[0]));
- if(String.valueOf(rowData[0]) != null && !String.valueOf(rowData[0]).equals("null") && !String.valueOf(rowData[0]).isEmpty()){
- // 显示一个简单的确认框
- int result = JOptionPane.showConfirmDialog(null, "确定要打印标签吗?", "确认",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE);
- if (result == JOptionPane.YES_OPTION) {
- System.out.println("用户点击了“是”");
- PrintUtil.printLabel(String.valueOf(rowData[0]),String.valueOf(rowData[2]),String.valueOf(rowData[3]),String.valueOf(rowData[1]));
- } else if (result == JOptionPane.NO_OPTION) {
- System.out.println("用户点击了“否”");
- } else if (result == JOptionPane.CLOSED_OPTION) {
- System.out.println("对话框被关闭");
- }
- // TestParam testParam = JdbcUtils.getTestData(2);
- // System.out.println(testParam.toString());
- // JSONObject retObj = DataUtil.qmResultData(testParam);
- // System.out.println(retObj.toString());
- }
- }
- }
- }
- });
- // 设置table的宽度为100%
- table.setRowHeight(40);
- table.setEnabled(true);
- table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
- // table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
- // table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
- // 设置第二列的长度为100像素
- TableColumn column = table.getColumnModel().getColumn(0);
- column.setPreferredWidth(290);
- column = table.getColumnModel().getColumn(1);
- column.setPreferredWidth(160);
- CenterRenderer centerRenderer = new CenterRenderer();
- for (int i = 0; i < table.getColumnCount(); i++) {
- table.getColumn(table.getColumnName(i)).setCellRenderer(centerRenderer);
- }
- // column = table.getColumnModel().getColumn(6);
- // column.setPreferredWidth(100);
- // column = table.getColumnModel().getColumn(7);
- // column.setPreferredWidth(100);
- JScrollPane scrollPane = new JScrollPane(table);
- panel.add(scrollPane);
- tabbedPane.addTab("记录查询", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
- indexPanelB = new JPanel();
- searchScrollPane = new JScrollPane(indexPanelB);
- indexPanelB.setLayout(null);
- //新增的面板
- JPanel indexPanelProductType = new JPanel();
- indexPanelProductType.setLayout(null);
- JScrollPane productTypeScrollPane = new JScrollPane(indexPanelProductType);
- JLabel productTypeTitle = new JLabel("生产类型设置");
- productTypeTitle.setFont(new Font("微软雅黑", Font.BOLD, 28));
- productTypeTitle.setForeground(new Color(64, 64, 64));
- productTypeTitle.setHorizontalAlignment(SwingConstants.CENTER);
- productTypeTitle.setBounds(81, 80, 810, 50);
- indexPanelProductType.add(productTypeTitle);
- JLabel productTypeHint = new JLabel("请选择当前生产的工件类型,切换后将保存到本地并用于扫码校验");
- productTypeHint.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- productTypeHint.setForeground(new Color(140, 140, 140));
- productTypeHint.setHorizontalAlignment(SwingConstants.CENTER);
- productTypeHint.setBounds(81, 140, 810, 40);
- indexPanelProductType.add(productTypeHint);
- productTypePanel = new ProductTypePanel(PRODUCT_TYPE_SWITCH_PASSWORD);
- productTypePanel.setBounds(276, 210, 420, 72);
- productTypePanel.setOnChangeListener(() -> {
- if (work_status == 0) {
- saveProductTypeToDb();
- setMenuStatus("当前生产类型:" + getProductTypeName() + ",请扫工件码", 0);
- }
- refreshProductTypeCurrentLabel();
- });
- indexPanelProductType.add(productTypePanel);
- productTypeCurrentLabel = new JLabel();
- productTypeCurrentLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));
- productTypeCurrentLabel.setForeground(new Color(64, 64, 64));
- productTypeCurrentLabel.setHorizontalAlignment(SwingConstants.CENTER);
- productTypeCurrentLabel.setBounds(81, 310, 810, 40);
- refreshProductTypeCurrentLabel();
- indexPanelProductType.add(productTypeCurrentLabel);
- tabbedPane.addTab("生产类型", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), productTypeScrollPane, null);
- tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
- indexPanelD = new JPanel();
- searchScrollPaneD = new JScrollPane(indexPanelD);
- indexPanelD.setLayout(null);
- PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
- String[] printerNames = (printServices != null && printServices.length > 0) ?
- new String[printServices.length] : new String[]{"未知"};
- for (int i = 0; i < printerNames.length; i++) {
- printerNames[i] = printServices[i].getName();
- }
- JLabel lblNewLabel_3 = new JLabel("设备程序号");
- lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3.setBounds(10, 22, 120, 30);
- // indexPanelD.add(lblNewLabel_3);
- programNo = new JTextField();
- programNo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- programNo.setBounds(140, 22, 200, 30);
- // indexPanelD.add(programNo);
- programNo.setColumns(10);
- JLabel lblNewLabel_3_1 = new JLabel("设备启动方式");
- lblNewLabel_3_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1.setBounds(10, 71, 120, 30);
- indexPanelD.add(lblNewLabel_3_1);
- startMode = new JComboBox();
- startMode.setModel(new DefaultComboBoxModel(new String[] {"手动启动", "自动启动"}));
- startMode.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- startMode.setBounds(140, 71, 200, 30);
- indexPanelD.add(startMode);
- JLabel lblNewLabel_3_1_1 = new JLabel("串口号");
- lblNewLabel_3_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1.setBounds(10, 123, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1);
- serialPort = new JTextField();
- serialPort.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- serialPort.setColumns(10);
- serialPort.setBounds(140, 123, 200, 30);
- indexPanelD.add(serialPort);
- JLabel lblNewLabel_3_1_1_1 = new JLabel("波特率");
- lblNewLabel_3_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1.setBounds(10, 176, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1);
- baudRate = new JTextField();
- baudRate.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- baudRate.setColumns(10);
- baudRate.setBounds(140, 176, 200, 30);
- indexPanelD.add(baudRate);
- JLabel lblNewLabel_3_1_1_1_1 = new JLabel("数据位");
- lblNewLabel_3_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1.setBounds(10, 229, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1);
- dataBits = new JComboBox();
- dataBits.setModel(new DefaultComboBoxModel(new String[] {"5", "6", "7", "8"}));
- dataBits.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- dataBits.setBounds(140, 229, 200, 30);
- indexPanelD.add(dataBits);
- JLabel lblNewLabel_3_1_1_1_1_1 = new JLabel("校验位");
- lblNewLabel_3_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1.setBounds(10, 282, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1);
- checkBit = new JComboBox();
- checkBit.setModel(new DefaultComboBoxModel(new String[] {"NONE", "ODD", "EVEN", "MARK", "SPACE"}));
- checkBit.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- checkBit.setBounds(140, 282, 200, 30);
- indexPanelD.add(checkBit);
- JLabel lblNewLabel_3_1_1_1_1_1_1 = new JLabel("停止位");
- lblNewLabel_3_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1.setBounds(10, 335, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1);
- stopBit = new JComboBox();
- stopBit.setModel(new DefaultComboBoxModel(new String[] {"1", "1.5", "2"}));
- stopBit.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- stopBit.setBounds(140, 335, 200, 30);
- indexPanelD.add(stopBit);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1 = new JLabel("是否打印标签");
- lblNewLabel_3_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1.setBounds(408, 22, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1);
- printLabel = new JComboBox();
- printLabel.setModel(new DefaultComboBoxModel(new String[] {"是", "否"}));
- printLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- printLabel.setBounds(536, 22, 200, 30);
- indexPanelD.add(printLabel);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1 = new JLabel("打印机名称");
- lblNewLabel_3_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1.setBounds(408, 71, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1);
- printName = new JTextField();
- printName.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- printName.setColumns(10);
- printName.setBounds(536, 71, 200, 30);
- indexPanelD.add(printName);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1 = new JLabel("标签名称");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30);
- // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1);
- labelName = new JTextField();
- labelName.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- labelName.setColumns(10);
- labelName.setBounds(536, 123, 200, 30);
- // indexPanelD.add(labelName);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移X");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setBounds(408, 176, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1);
- labelx = new JTextField();
- labelx.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- labelx.setColumns(10);
- labelx.setBounds(536, 176, 200, 30);
- indexPanelD.add(labelx);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移Y");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 229, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1);
- labely = new JTextField();
- labely.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- labely.setColumns(10);
- labely.setBounds(536, 229, 200, 30);
- indexPanelD.add(labely);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签行间距");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 282, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1);
- labelLineSpace = new JTextField();
- labelLineSpace.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- labelLineSpace.setColumns(10);
- labelLineSpace.setBounds(536, 282, 200, 30);
- indexPanelD.add(labelLineSpace);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签字号");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 335, 120, 30);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1);
- labelFont = new JTextField();
- labelFont.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- labelFont.setColumns(10);
- // labelFont.setBounds(536, 335, 200, 30);
- labelFont.setBounds(536, 123, 200, 30);
- indexPanelD.add(labelFont);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("MODBUS站号");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 282, 120, 30);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 335, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2);
- stationNo = new JTextField();
- stationNo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- stationNo.setColumns(10);
- stationNo.setBounds(536, 335, 200, 30);
- indexPanelD.add(stationNo);
- saveBtn = new JButton("编辑配置");
- saveBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- saveBtn.setBounds(787, 267, 156, 57);
- indexPanelD.add(saveBtn);
- saveBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(isConfigEdit == 0){
- String pass = "503833";
- //弹窗扫工件码
- String scanBarcode = JOptionPane.showInputDialog(null, "请输入密码");
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")&&scanBarcode.equals(pass)) {
- isConfigEdit = 1;
- formatConfigEdit(true);
- saveBtn.setText("保存配置");
- }else{
- MesClient.setMenuStatus("密码错误",-1);
- }
- }else{
- formatConfigEdit(false);
- saveBtn.setText("编辑配置");
- configParam.setProgramNo(programNo.getText());
- configParam.setSerialPort(serialPort.getText());
- configParam.setBaudRate(baudRate.getText());
- configParam.setPrintName(printName.getText());
- configParam.setLabelName(labelName.getText());
- configParam.setLabelx(labelx.getText());
- configParam.setLabely(labely.getText());
- configParam.setLabelLineSpace(labelLineSpace.getText());
- configParam.setLabelFont(labelFont.getText());
- configParam.setStationNo(stationNo.getText());
- configParam.setStopBit(stopBit.getSelectedItem().toString());
- configParam.setCheckBit(checkBit.getSelectedItem().toString());
- configParam.setStopBit(stopBit.getSelectedItem().toString());
- configParam.setDataBits(dataBits.getSelectedItem().toString());
- configParam.setPrintLabel(printLabel.getSelectedItem().toString());
- configParam.setStartMode(startMode.getSelectedItem().toString());
- configParam.setProductSnPre(productSnPre.getText().trim());
- configParam.setProductSnLength(productSnLength.getText().trim());
- configParam.setLeakage(leakage.getSelectedItem().toString());
- configParam.setDevice(device.getSelectedItem().toString());
- //9.1修改
- // configParam.setNgTime(ngTime.getText());
- // configParam.setNgNumber(ngNumber.getText());
- // configParam.setNgUpgradeTime(ngUpgradeTime.getText());
- configParam.setOprno(oprno.getText().trim());
- configParam.setOprnoTitle(oprnoTitle.getText().trim());
- configParam.setLineSn(lineSn.getText().trim());
- System.out.println("configParam:"+JSONObject.toJSONString(configParam));
- if(configParam.getId() != null && configParam.getId() > 0){
- JdbcUtils.updateConfig(configParam.getId(),JSONObject.toJSONString(configParam));
- }else{
- JdbcUtils.insertConfig(JSONObject.toJSONString(configParam));
- }
- isConfigEdit = 0;
- // MesClient.indexPanelB.removeAll();
- // System.out.println("indexPanelB:"+MesClient.indexPanelB.getComponentCount());
- // MesClient.jfxPanel2 = null;
- // if(MesClient.jfxPanel2 == null){
- // String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+MesClient.user_menu.getText()+"&oprno="+MesClient.configParam.getOprno()+"&lineSn="+MesClient.mes_line_sn;
- // MesClient.jfxPanel2 = new MesWebView(url);
- // MesClient.jfxPanel2.setSize(990, 550);
- // MesClient.indexPanelB.add(MesClient.jfxPanel2);
- // System.out.println("indexPanelBB:"+MesClient.indexPanelB.getComponentCount());
- // MesClient.indexPanelB.revalidate(); // 重新验证布局(如果需要)
- // MesClient.indexPanelB.repaint();
- // System.out.println("indexPanelCC:"+MesClient.indexPanelB.getComponentCount());
- // }
- formatConfigData();
- serialPortUtils.closePort();
- serialPortUtils = new SerialPortUtils(configParam.getSerialPort(),getEffectiveOprno(),configParam.getOprnoTitle(),configParam.getDevice());
- }
- }
- });
- JLabel lblNewLabel_3_1_1_1_1_1_1_2 = new JLabel("泄露值取值");
- lblNewLabel_3_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 445, 120, 30);
- // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(408, 390, 120, 30);
- lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_2);
- leakage = new JComboBox();
- leakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"}));
- leakage.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // leakage.setBounds(140, 445, 200, 30);
- // leakage.setBounds(536, 390, 200, 30);
- leakage.setBounds(140, 390, 200, 30);
- indexPanelD.add(leakage);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码长度");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 390, 120, 30);
- // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1);
- productSnLength = new JTextField();
- productSnLength.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- productSnLength.setColumns(10);
- productSnLength.setBounds(536, 390, 200, 30);
- // indexPanelD.add(productSnLength);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码前缀");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(10, 390, 120, 30);
- // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1);
- productSnPre = new JTextField();
- productSnPre.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- productSnPre.setColumns(10);
- productSnPre.setBounds(140, 390, 200, 30);
- // indexPanelD.add(productSnPre);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("检测设备");
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 445, 120, 30);
- // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30);
- lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 22, 120, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2);
- device = new JComboBox();
- device.setModel(new DefaultComboBoxModel(new String[] {"innomatec", "ateq"}));
- device.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // device.setBounds(536, 445, 200, 30);
- // device.setBounds(140, 390, 200, 30);
- device.setBounds(140, 22, 200, 30);
- indexPanelD.add(device);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2 = new JLabel("工位号");
- lblNewLabel_3_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.CENTER);
- lblNewLabel_3_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_2.setBounds(762, 22, 200, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2);
- // ngTime = new JTextField();
- // ngTime.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // ngTime.setColumns(10);
- // ngTime.setBounds(762, 54, 200, 30);
- // indexPanelD.add(ngTime);
- oprno = new JTextField();
- oprno.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- oprno.setColumns(10);
- oprno.setBounds(762, 54, 200, 30);
- indexPanelD.add(oprno);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1 = new JLabel("工位名称");
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setHorizontalAlignment(SwingConstants.CENTER);
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setBounds(762, 94, 200, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1);
- // ngNumber = new JTextField();
- // ngNumber.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // ngNumber.setColumns(10);
- // ngNumber.setBounds(762, 123, 200, 30);
- // indexPanelD.add(ngNumber);
- oprnoTitle = new JTextField();
- oprnoTitle.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- oprnoTitle.setColumns(10);
- oprnoTitle.setBounds(762, 123, 200, 30);
- indexPanelD.add(oprnoTitle);
- JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1 = new JLabel("产线编号");
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setHorizontalAlignment(SwingConstants.CENTER);
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setBounds(762, 163, 200, 30);
- indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1);
- //
- // ngUpgradeTime = new JTextField();
- // ngUpgradeTime.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // ngUpgradeTime.setColumns(10);
- // ngUpgradeTime.setBounds(762, 195, 200, 30);
- // indexPanelD.add(ngUpgradeTime);
- lineSn = new JTextField();
- lineSn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- lineSn.setColumns(10);
- lineSn.setBounds(762, 195, 200, 30);
- indexPanelD.add(lineSn);
- tabbedPane.addTab("软件设置", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), searchScrollPaneD, null);
- JPanel indexPanelTask = new JPanel();
- searchScrollPaneTask = new JScrollPane(indexPanelTask);
- indexPanelTask.setLayout(null);
- JPanel panel22 = new JPanel();
- panel22.setBounds(0, 0, 300, 530);
- indexPanelTask.add(panel22);
- panel22.setLayout(new GridLayout(0, 1, 0, 0));
- table2 = new JTable(rowData2, columnNames2){
- public boolean isCellEditable(int row, int column) {
- return false;
- }
- };
- table2.setRowHeight(40);
- table2.setEnabled(true);
- table2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
- // 添加鼠标点击事件
- table2.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- // 获取点击位置的行和列索引
- int row = table2.rowAtPoint(e.getPoint());
- int col = table2.columnAtPoint(e.getPoint());
- // 检查点击是否有效(即是否真的在表格内)
- if (row >= 0 && col >= 0) {
- // 获取点击的单元格的值
- Object value = table2.getValueAt(row, col);
- String val = String.valueOf(value);
- System.out.println("Clicked on row " + row + ", column " + col + ": " + value);
- // 在这里添加你的逻辑代码
- for(TaskParam taskParam:taskParamList){
- if(val.equals(taskParam.getTitle())){
- MesClient.curTaskParam = taskParam;
- formatTaskParam();
- break;
- }
- }
- }
- }
- });
- // 自定义渲染器
- DefaultTableCellRenderer centerRenderer2 = new DefaultTableCellRenderer();
- centerRenderer2.setHorizontalAlignment(JLabel.CENTER); // 设置内容居中
- table2.setDefaultRenderer(Object.class, centerRenderer2); // 应用到所有列
- JScrollPane scrollPane2 = new JScrollPane(table2);
- panel22.add(scrollPane2);
- JButton addTask = new JButton("新增任务");
- addTask.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String taskContent = JOptionPane.showInputDialog(null, "请输入任务名称").trim();
- if(taskContent!=null&&!taskContent.equalsIgnoreCase("")) {
- String passContent = JOptionPane.showInputDialog(null, "请输入密码");
- if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
- if(passContent.equals("503833")){
- int wyflag = 1;
- for(TaskParam taskParam:taskParamList){
- if(taskParam.getTitle().equals(taskContent)){
- wyflag = 0;
- break;
- }
- }
- if(wyflag == 0){
- MesClient.setMenuStatus("任务名称已被占用",-1);
- return;
- }
- TaskParam taskParam = new TaskParam();
- taskParam.setTitle(taskContent);
- JdbcUtils.insertTask(taskParam);
- getTask();
- }else{
- MesClient.setMenuStatus("密码错误",-1);
- }
- }
- }
- }
- });
- addTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- addTask.setBounds(310, 10, 120, 40);
- indexPanelTask.add(addTask);
- JButton delTask = new JButton("删除任务");
- delTask.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(MesClient.curTaskParam == null){
- MesClient.setMenuStatus("请先选择任务",-1);
- return;
- }
- String passContent = JOptionPane.showInputDialog(null, "请输入密码");
- if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
- if(passContent.equals("503833")){
- JdbcUtils.deleteTask(MesClient.curTaskParam.getId());
- getTask();
- MesClient.curTaskParam = null;
- formatTaskParam();
- }else{
- MesClient.setMenuStatus("密码错误",-1);
- }
- }
- }
- });
- delTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- delTask.setBounds(440, 10, 120, 40);
- indexPanelTask.add(delTask);
- JButton saveTask = new JButton("保存任务");
- saveTask.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(MesClient.curTaskParam == null){
- MesClient.setMenuStatus("请先选择任务",-1);
- return;
- }
- String passContent = JOptionPane.showInputDialog(null, "请输入密码");
- if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
- if(passContent.equals("503833")){
- MesClient.curTaskParam.setBarcodeSpecStart(barcodeSpecStart.getText().trim());
- MesClient.curTaskParam.setBarcodeSpec(barcodeSpec.getText().trim());
- MesClient.curTaskParam.setBarcodeLength(barcodeLength.getText().trim());
- MesClient.curTaskParam.setTaskProgramNo(taskMaxNumA.getText().trim());
- MesClient.curTaskParam.setTaskLabelName(taskMaxFoutA.getText().trim());
- MesClient.curTaskParam.setTaskLeakage(taskLeakage.getSelectedItem().toString());
- JdbcUtils.updateTask(MesClient.curTaskParam.getId(),MesClient.curTaskParam);
- getTask();
- formatTaskParam();
- }else{
- MesClient.setMenuStatus("密码错误",-1);
- }
- }
- }
- });
- saveTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- saveTask.setBounds(570, 10, 120, 40);
- indexPanelTask.add(saveTask);
- taskName = new JLabel("");
- taskName.setFont(new Font("微软雅黑", Font.PLAIN, 20));
- taskName.setBounds(700, 10, 283, 40);
- indexPanelTask.add(taskName);
- JLabel taskMaxNumLabelA = new JLabel("程序号");
- taskMaxNumLabelA.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxNumLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxNumLabelA.setBounds(310, 93, 110, 30);
- indexPanelTask.add(taskMaxNumLabelA);
- taskMaxNumA = new JTextField();
- taskMaxNumA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxNumA.setBounds(422, 93, 110, 30);
- indexPanelTask.add(taskMaxNumA);
- taskMaxNumA.setColumns(10);
- JLabel taskMaxFoutLabelA = new JLabel("标签名称");
- taskMaxFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxFoutLabelA.setBounds(310, 133, 110, 30);
- indexPanelTask.add(taskMaxFoutLabelA);
- taskMaxFoutA = new JTextField();
- taskMaxFoutA.setColumns(10);
- taskMaxFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxFoutA.setBounds(422, 133, 110, 30);
- indexPanelTask.add(taskMaxFoutA);
- JLabel taskMinFoutLabelA = new JLabel("泄漏值取值");
- taskMinFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
- taskMinFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinFoutLabelA.setBounds(310, 173, 110, 30);
- indexPanelTask.add(taskMinFoutLabelA);
- taskLeakage = new JComboBox();
- taskLeakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"}));
- taskLeakage.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskLeakage.setBounds(422, 173, 110, 30);
- indexPanelTask.add(taskLeakage);
- // taskMinFoutA = new JTextField();
- // taskMinFoutA.setColumns(10);
- // taskMinFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- // taskMinFoutA.setBounds(422, 173, 110, 30);
- // indexPanelTask.add(taskMinFoutA);
- JLabel taskMaxSoutLabelA = new JLabel("A枪最大行程");
- taskMaxSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxSoutLabelA.setBounds(310, 213, 110, 30);
- // indexPanelTask.add(taskMaxSoutLabelA);
- taskMaxSoutA = new JTextField();
- taskMaxSoutA.setColumns(10);
- taskMaxSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxSoutA.setBounds(422, 213, 110, 30);
- // indexPanelTask.add(taskMaxSoutA);
- JLabel taskMinSoutLabelA = new JLabel("A枪最小行程");
- taskMinSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
- taskMinSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinSoutLabelA.setBounds(310, 253, 110, 30);
- // indexPanelTask.add(taskMinSoutLabelA);
- taskMinSoutA = new JTextField();
- taskMinSoutA.setColumns(10);
- taskMinSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinSoutA.setBounds(422, 253, 110, 30);
- // indexPanelTask.add(taskMinSoutA);
- JLabel taskMaxNumLabelB = new JLabel("B枪预算数量");
- taskMaxNumLabelB.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxNumLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxNumLabelB.setBounds(580, 93, 110, 30);
- // indexPanelTask.add(taskMaxNumLabelB);
- taskMaxNumB = new JTextField();
- taskMaxNumB.setColumns(10);
- taskMaxNumB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxNumB.setBounds(692, 93, 110, 30);
- // indexPanelTask.add(taskMaxNumB);
- JLabel taskMaxFoutLabelB = new JLabel("B枪最大拉力");
- taskMaxFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxFoutLabelB.setBounds(580, 133, 110, 30);
- // indexPanelTask.add(taskMaxFoutLabelB);
- taskMaxFoutB = new JTextField();
- taskMaxFoutB.setColumns(10);
- taskMaxFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxFoutB.setBounds(692, 133, 110, 30);
- // indexPanelTask.add(taskMaxFoutB);
- JLabel taskMinFoutLabelB = new JLabel("B枪最小拉力");
- taskMinFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
- taskMinFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinFoutLabelB.setBounds(580, 173, 110, 30);
- // indexPanelTask.add(taskMinFoutLabelB);
- taskMinFoutB = new JTextField();
- taskMinFoutB.setColumns(10);
- taskMinFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinFoutB.setBounds(692, 173, 110, 30);
- // indexPanelTask.add(taskMinFoutB);
- JLabel taskMaxSoutLabelB = new JLabel("B枪最大行程");
- taskMaxSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
- taskMaxSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxSoutLabelB.setBounds(580, 213, 110, 30);
- // indexPanelTask.add(taskMaxSoutLabelB);
- taskMaxSoutB = new JTextField();
- taskMaxSoutB.setColumns(10);
- taskMaxSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMaxSoutB.setBounds(692, 213, 110, 30);
- // indexPanelTask.add(taskMaxSoutB);
- JLabel taskMinSoutLabelB = new JLabel("B枪最小行程");
- taskMinSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
- taskMinSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinSoutLabelB.setBounds(580, 253, 110, 30);
- // indexPanelTask.add(taskMinSoutLabelB);
- taskMinSoutB = new JTextField();
- taskMinSoutB.setColumns(10);
- taskMinSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- taskMinSoutB.setBounds(692, 253, 110, 30);
- // indexPanelTask.add(taskMinSoutB);
- JLabel barcodeSpecLabel = new JLabel("条码固定位");
- barcodeSpecLabel.setHorizontalAlignment(SwingConstants.CENTER);
- barcodeSpecLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeSpecLabel.setBounds(310, 293, 110, 30);
- indexPanelTask.add(barcodeSpecLabel);
- barcodeSpec = new JTextField();
- barcodeSpec.setColumns(10);
- barcodeSpec.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeSpec.setBounds(422, 293, 110, 30);
- indexPanelTask.add(barcodeSpec);
- JLabel barcodeSpecStartLabel = new JLabel("起始位数");
- barcodeSpecStartLabel.setHorizontalAlignment(SwingConstants.CENTER);
- barcodeSpecStartLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeSpecStartLabel.setBounds(310, 333, 110, 30);
- indexPanelTask.add(barcodeSpecStartLabel);
- barcodeSpecStart = new JTextField();
- barcodeSpecStart.setColumns(10);
- barcodeSpecStart.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeSpecStart.setBounds(422, 333, 110, 30);
- indexPanelTask.add(barcodeSpecStart);
- JLabel barcodeLengthLabel = new JLabel("条码长度");
- barcodeLengthLabel.setHorizontalAlignment(SwingConstants.CENTER);
- barcodeLengthLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeLengthLabel.setBounds(310, 373, 110, 30);
- indexPanelTask.add(barcodeLengthLabel);
- barcodeLength = new JTextField();
- barcodeLength.setColumns(10);
- barcodeLength.setFont(new Font("微软雅黑", Font.PLAIN, 16));
- barcodeLength.setBounds(422, 373, 110, 30);
- indexPanelTask.add(barcodeLength);
- tabbedPane.addTab("任务设置", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneTask, null);
- tabbedPane.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
- int selectedIndex = tabbedPane.getSelectedIndex();
- if(selectedIndex == 1){
- }
- JdbcUtils.getTestData();
- }
- });
- }
- private static String validateProductSnMessage(String sn) {
- if (sn == null || sn.isEmpty()) {
- return "工件码为空,请重试";
- }
- if (sn.length() != PRODUCT_SN_LENGTH) {
- return "工件码长度须为32位,当前" + sn.length() + "位";
- }
- String prefix = getProductSnPrefix();
- if (!sn.startsWith(prefix)) {
- return "工件码前缀与当前类型(" + getProductTypeName() + ")不匹配,当前工件码为" + getProductTypeNameBySn(sn);
- }
- return null;
- }
- private static void updateProductTypePanelEnabled(boolean enabled) {
- if (productTypePanel != null) {
- productTypePanel.setEnabled(enabled);
- }
- }
- public static void loadProductTypeFromDb() {
- if (productTypePanel == null) {
- return;
- }
- String savedType = JdbcUtils.getClientConfig(
- JdbcUtils.getProductTypeConfigKey(mes_gw),
- PRODUCT_TYPE_ZJ
- );
- if (PRODUCT_TYPE_SJ.equals(savedType)) {
- productTypePanel.setResult(PRODUCT_TYPE_SJ);
- } else {
- productTypePanel.setResult(PRODUCT_TYPE_ZJ);
- }
- refreshProductTypeCurrentLabel();
- }
- public static void refreshProductTypeCurrentLabel() {
- if (productTypeCurrentLabel != null) {
- productTypeCurrentLabel.setText("当前选择:" + getProductTypeName() + "(前缀 " + getProductSnPrefix() + ")");
- }
- }
- public static void saveProductTypeToDb() {
- if (productTypePanel == null) {
- return;
- }
- JdbcUtils.saveClientConfig(
- JdbcUtils.getProductTypeConfigKey(mes_gw),
- productTypePanel.getResult()
- );
- }
- public static String getProductSnPrefix() {
- if (productTypePanel != null && PRODUCT_TYPE_SJ.equals(productTypePanel.getResult())) {
- return PREFIX_SJ;
- }
- return PREFIX_ZJ;
- }
- public static String getProductTypeName() {
- if (productTypePanel != null) {
- return productTypePanel.getTypeName();
- }
- return "智界";
- }
- private static String getProductTypeNameBySn(String sn) {
- if (sn.startsWith(PREFIX_SJ)) {
- return "尚界";
- }
- if (sn.startsWith(PREFIX_ZJ)) {
- return "智界";
- }
- return "未知";
- }
- public static void setMenuStatus(String msg,int error){
- if(error == 0){
- MesClient.status_menu.setForeground(Color.GREEN);
- }else{
- MesClient.status_menu.setForeground(Color.RED);
- }
- MesClient.status_menu.setText(msg);
- }
- public static void getTask(){
- taskParamList = JdbcUtils.getTask();
- System.out.println("taskParamList:"+taskParamList.size());
- if(taskParamList.size() > 0){
- int i = 0;
- rowData2 = new Object[taskParamList.size()][1];
- for(TaskParam taskParam:taskParamList){
- rowData2[i][0] = taskParam.getTitle();
- i++;
- }
- }else{
- rowData2[0][0] = "";
- }
- System.out.println("rowData2:"+JSONObject.toJSONString(rowData2));
- DefaultTableModel model = new DefaultTableModel(rowData2, columnNames2);
- table2.setModel(model);
- MesClient.table2.repaint();
- }
- public static void formatTaskParam(){
- if(MesClient.curTaskParam != null){
- taskName.setText(MesClient.curTaskParam.getTitle());
- if(MesClient.curTaskParam.getTaskProgramNo() == null || MesClient.curTaskParam.getTaskProgramNo().equals("")){
- MesClient.curTaskParam.setTaskProgramNo("");
- }
- taskMaxNumA.setText(MesClient.curTaskParam.getTaskProgramNo());
- if(MesClient.curTaskParam.getTaskLabelName() == null || MesClient.curTaskParam.getTaskLabelName().equals("")){
- MesClient.curTaskParam.setTaskLabelName("");
- }
- taskMaxFoutA.setText(MesClient.curTaskParam.getTaskLabelName());
- if(MesClient.curTaskParam.getTaskLeakage() == null || MesClient.curTaskParam.getTaskLeakage().equals("")){
- MesClient.curTaskParam.setTaskLeakage("压降");
- }
- taskLeakage.setSelectedItem(MesClient.curTaskParam.getTaskLeakage());
- if(MesClient.curTaskParam.getBarcodeSpec() == null || MesClient.curTaskParam.getBarcodeSpec().equals("")){
- MesClient.curTaskParam.setBarcodeSpec("");
- }
- barcodeSpec.setText(MesClient.curTaskParam.getBarcodeSpec());
- if(MesClient.curTaskParam.getBarcodeSpecStart() == null || MesClient.curTaskParam.getBarcodeSpecStart().equals("")){
- MesClient.curTaskParam.setBarcodeSpecStart("");
- }
- barcodeSpecStart.setText(MesClient.curTaskParam.getBarcodeSpecStart());
- if(MesClient.curTaskParam.getBarcodeLength() == null || MesClient.curTaskParam.getBarcodeLength().equals("")){
- MesClient.curTaskParam.setBarcodeLength("");
- }
- barcodeLength.setText(MesClient.curTaskParam.getBarcodeLength());
- }else{
- taskName.setText("");
- taskMaxNumA.setText("");
- taskMaxNumB.setText("");
- taskMaxFoutA.setText("");
- taskMaxFoutB.setText("");
- taskMaxSoutA.setText("");
- taskMaxSoutB.setText("");
- taskMinFoutA.setText("");
- taskMinFoutB.setText("");
- taskMinSoutA.setText("");
- taskMinSoutB.setText("");
- barcodeLength.setText("");
- barcodeSpec.setText("");
- barcodeSpecStart.setText("");
- }
- }
- // 检查工件码的正确性
- public static boolean checkProductSn(String sn){
- curTaskName.setText("");
- if(taskParamList.size() <= 0){
- MesClient.setMenuStatus("未设置任务",-1);
- return false;
- }
- try{
- for(TaskParam taskParam : taskParamList){
- if(taskParam.getBarcodeSpec()!=null&&!taskParam.getBarcodeSpec().equals("null")&&taskParam.getBarcodeSpecStart()!=null&&!taskParam.getBarcodeSpecStart().equals("null")&&taskParam.getBarcodeLength()!=null&&!taskParam.getBarcodeLength().equals("null")) {
- Boolean ret = CommonUtils.checkSnByModel(sn,taskParam.getBarcodeSpec(),Integer.valueOf(taskParam.getBarcodeSpecStart()),Integer.valueOf(taskParam.getBarcodeLength()));
- if(ret){
- configParam.setLabelName(taskParam.getTaskLabelName());
- configParam.setLeakage(taskParam.getTaskLeakage());
- configParam.setProgramNo(taskParam.getTaskProgramNo());
- curTaskName.setText("当前任务:"+taskParam.getTitle());
- // configParam.setDeviceMaxNumValA(taskParam.getTaskMaxNumA());
- // configParam.setMaxFoutValA(taskParam.getTaskMaxFoutA());
- // configParam.setMaxSoutValA(taskParam.getTaskMaxSoutA());
- // configParam.setMinFoutValA(taskParam.getTaskMinFoutA());
- // configParam.setMinSoutValA(taskParam.getTaskMinSoutA());
- //
- // configParam.setDeviceMaxNumValB(taskParam.getTaskMaxNumB());
- // configParam.setMaxFoutValB(taskParam.getTaskMaxFoutB());
- // configParam.setMaxSoutValB(taskParam.getTaskMaxSoutB());
- // configParam.setMinFoutValB(taskParam.getTaskMinFoutB());
- // configParam.setMinSoutValB(taskParam.getTaskMinSoutB());
- return true;
- }
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- MesClient.setMenuStatus("该类型工件未设置任务",-1);
- return false;
- }
- public static void getMaterailData(){
- try{
- JSONObject retObj = DataUtil.getBindMaterail();
- if(retObj == null){
- return;
- }
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
- int i = 0;
- materialRowData = new Object[arrs.size()][7];
- for (BindMaterialResp bindMaterialResp:arrs){
- materialRowData[i][0] = bindMaterialResp.getMaterialTitle();
- materialRowData[i][1] = bindMaterialResp.getBatchSn();
- materialRowData[i][2] = bindMaterialResp.getLastTimes();
- materialRowData[i][3] = "";
- materialRowData[i][4] = bindMaterialResp.getCraft();
- materialRowData[i][5] = bindMaterialResp.getMaterialId();
- materialRowData[i][6] = bindMaterialResp.getType();
- i++;
- }
- bindBatchPanel();
- }
- }catch (Exception e){
- log.info(e.getMessage());
- }
- }
- public static void updateMaterailData(){
- try{
- if(materialRowData == null){
- return;
- }
- JSONObject retObj = DataUtil.getBindMaterail();
- if(retObj == null){
- return;
- }
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
- int i = 0;
- for (BindMaterialResp bindMaterialResp:arrs){
- materialRowData[i][0] = bindMaterialResp.getMaterialTitle();
- materialRowData[i][1] = bindMaterialResp.getBatchSn();
- materialRowData[i][2] = bindMaterialResp.getLastTimes();
- materialRowData[i][3] = "";
- materialRowData[i][4] = bindMaterialResp.getCraft();
- materialRowData[i][5] = bindMaterialResp.getMaterialId();
- materialRowData[i][6] = bindMaterialResp.getType();
- i++;
- }
- if(materialTable != null){
- materialTable.repaint();
- }
- }
- }catch (Exception e){
- log.info(e.getMessage());
- }
- }
- public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
- String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
- String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
- if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
- JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
- if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
- MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
- updateMaterailData();
- }else{
- if(retObj.get("result")==null){
- MesClient.setMenuStatus("请求失败,请重试",-1);
- }else{
- if(retObj.get("result").toString().equalsIgnoreCase("false")){
- MesClient.setMenuStatus(retObj.getString("message"),-1);
- }
- }
- }
- }
- }
- public static void bindBatchPanel(){
- JPanel indexPanelBB = new JPanel();
- JPanel panel = new JPanel();
- panel.setBounds(0, 0, 990, 550);
- indexPanelBB.add(panel);
- panel.setLayout(new GridLayout(0, 1, 0, 0));
- materialTable = new JTable(materialRowData, materialColumnNames){
- public boolean isCellEditable(int row, int column) {
- if(column == 3){
- return true;
- }
- return false;
- }
- };
- materialTable.setRowHeight(40);
- materialTable.setEnabled(true);
- materialTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
- materialTable.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
- materialTable.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
- JScrollPane scrollPane = new JScrollPane(materialTable);
- panel.add(scrollPane);
- JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
- indexPanelBB.setLayout(null);
- tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
- }
- }
|