📄 gfmcheckercomposite.java
字号:
package com.cmspad.dmp.bundles.gfm.widget;import java.io.ByteArrayInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Map;import org.eclipse.swt.SWT;import org.eclipse.swt.events.DisposeEvent;import org.eclipse.swt.events.DisposeListener;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.program.Program;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Combo;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import com.cmspad.dmp.DMPApplication;import com.cmspad.dmp.DMPDatabase;import com.cmspad.dmp.DMPException;import com.cmspad.dmp.DMPProject;public class GFMCheckerComposite extends Composite { private Button loadButton; /** * 当前录入人员的编号 */ private long uId; /** * 当前工作作业的编号 */ private long pId; /** * 当前工作画像的编号 */ private long iId; /** * 当前工作画像的名称 */ private String iName; /** * 当前工作画像的文件 */ private File iFile; private String iPath; /** * 是否需要校验 */ private boolean hasv; private Combo combo; private Button nextButton; private Button flagButton; public GFMCheckerComposite(Shell parent, long uid, long pid) { super(parent, SWT.NONE); this.uId = uid; this.pId = pid; addDisposeListener(new DisposeListener() { public void widgetDisposed(final DisposeEvent e) { if(iId > 0){ DMPProject.Data.reset(iId, uId, DMPProject.Status.CHECKING); } } }); final GridLayout gridLayout = new GridLayout(); gridLayout.verticalSpacing = 2; gridLayout.horizontalSpacing = 2; gridLayout.marginWidth = 2; gridLayout.marginHeight = 2; gridLayout.numColumns = 6; setLayout(gridLayout); final Label label = new Label(this, SWT.NONE); label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true)); label.setText("作业"); combo = new Combo(this, SWT.READ_ONLY); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { int index = combo.getSelectionIndex(); if (index > -1) { Long pid = (Long) combo.getData("N:" + combo.getText()); if (pid != null) { nextProject(pid); } } } }); combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); nextButton = new Button(this, SWT.NONE); nextButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { nextImage(false); } }); final GridData gd_nextButton = new GridData(SWT.LEFT, SWT.CENTER, false, true); gd_nextButton.widthHint = 60; nextButton.setLayoutData(gd_nextButton); nextButton.setText("下一页"); loadButton = new Button(this, SWT.NONE); loadButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { loadImage(); } }); final GridData gd_loadButton = new GridData(SWT.LEFT, SWT.CENTER, false, true); gd_loadButton.widthHint = 60; loadButton.setLayoutData(gd_loadButton); loadButton.setText("重 载"); flagButton = new Button(this, SWT.NONE); flagButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { nextImage(true); } }); final GridData gd_flagButton = new GridData(SWT.LEFT, SWT.CENTER, false, true); gd_flagButton.widthHint = 60; flagButton.setLayoutData(gd_flagButton); flagButton.setText("有 错"); final Button button_1 = new Button(this, SWT.NONE); button_1.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { getShell().close(); } }); final GridData gd_button_1 = new GridData(SWT.LEFT, SWT.CENTER, false, true); gd_button_1.widthHint = 60; button_1.setLayoutData(gd_button_1); button_1.setText("关 闭"); // initProject(); } @Override protected void checkSubclass() {} private void loadImage() { if (iFile != null && iFile.exists()) { iFile.delete(); } if (iId > 0) { // 获取文件 byte[] iByte = DMPProject.Data.getData(iId, DMPProject.Status.INPUTING, true); File oFile = DMPProject.Data.getFile(iId); // iFile = new File(System.getProperty("user.dir") + File.separator + "tmp" + File.separator + "com.cmspad.dmp.bundles.gfm" + File.separator + "temp" + File.separator + "c_" + oFile.getName()); try { ByteArrayInputStream is = new ByteArrayInputStream(iByte); FileOutputStream os = new FileOutputStream(iFile); byte[] cache = new byte[4096]; for (int i = is.read(cache); i != -1; i = is.read(cache)) { os.write(cache, 0, i); } is.close(); os.close(); } catch (IOException e) { throw new DMPException("保存数据文件时出现文件读写错误", e); } // 打开文件 launchProg(); } else { nextButton.setEnabled(false); loadButton.setEnabled(false); flagButton.setEnabled(false); } } private void nextImage(boolean haserr) { // 如果有文件,则先保存文件。 if (iFile != null && iFile.exists()) { saveImage(haserr); iFile.delete(); } // 获取下一个文件 Map<String, Object> info = DMPProject.Data.next(pId, uId, DMPProject.Status.CHECKING, hasv); if (info != null) { iId = (Long) info.get("id"); iName = (String)info.get("name"); getShell().setText("检查终端 v" + DMPApplication.VERSION + ": " + iName); // 获取文件 File oFile = DMPProject.Data.getFile(iId); iFile = new File(System.getProperty("user.dir") + File.separator + "tmp" + File.separator + "com.cmspad.dmp.bundles.gfm" + File.separator + "temp" + File.separator + "c_" + oFile.getName()); byte[] iByte = DMPProject.Data.getData(iId, DMPProject.Status.INPUTING, true); try { ByteArrayInputStream is = new ByteArrayInputStream(iByte); FileOutputStream os = new FileOutputStream(iFile); byte[] cache = new byte[4096]; for (int i = is.read(cache); i != -1; i = is.read(cache)) { os.write(cache, 0, i); } is.close(); os.close(); } catch (IOException e) { throw new DMPException("保存数据文件时出现文件读写错误", e); } // 打开文件 launchProg(); } else { getShell().setText("检查终端 v" + DMPApplication.VERSION); nextButton.setEnabled(false); loadButton.setEnabled(false); flagButton.setEnabled(false); } } private void saveImage(boolean haserr) { try { FileInputStream fis = new FileInputStream(iFile); DMPProject.Data.setData(iId, fis, uId, DMPProject.Status.CHECKING, haserr, false, hasv); fis.close(); } catch (IOException e) { throw new DMPException("保存录入数据时出现文件读写错误", e); } } private void nextProject(long pid) { this.pId = pid; this.iId = -1; Map<DMPProject.Column, Object> project = DMPProject.getByPID(pid); hasv = (Boolean) project.get(DMPProject.Column.ENABLE_VERIFY); try{ Connection conn = DMPDatabase.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT p_prog FROM gfm_project WHERE p_id = ?"); stmt.setLong(1, pId); ResultSet rs = stmt.executeQuery(); if(rs.next()){ iPath = rs.getString(1); } rs.close(); stmt.close(); conn.close(); }catch(SQLException e){ throw new DMPException("获取作业信息时出现数据库错误", e); } nextButton.setEnabled(true); loadButton.setEnabled(true); flagButton.setEnabled(true); } private void initProject() { // 初始化作业列表 DMPProject.fillProjectList(combo, DMPApplication.Type.C, uId, pId, "com.cmspad.dmp.bundles.gfm"); // 初始化目录 File bdedir = new File(System.getProperty("user.dir") + File.separator + "tmp" + File.separator + "com.cmspad.dmp.bundles.gfm"); if (!bdedir.exists()) { bdedir.mkdir(); bdedir.deleteOnExit(); } File tmpdir = new File(System.getProperty("user.dir") + File.separator + "tmp" + File.separator + "com.cmspad.dmp.bundles.gfm" + File.separator + "temp"); if (!tmpdir.exists()) { tmpdir.mkdir(); tmpdir.deleteOnExit(); } // 初始化作业 nextProject(pId); } private void launchProg(){ if(iPath != null && new File(iPath).exists()){ try { Runtime.getRuntime().exec(new String[]{iPath, iFile.getAbsolutePath()}); } catch (IOException e) { throw new DMPException("打开应用程序时出现文件读写错误", e); } }else{ Program.launch(iFile.getAbsolutePath()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -