gfminputercomposite.java
来自「BPO作业管理系统DMP的插件」· Java 代码 · 共 313 行
JAVA
313 行
package com.cmspad.dmp.bundles.gfm.widget;import java.io.File;import java.io.FileInputStream;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 GFMInputerComposite extends Composite { private Button loadButton; private Button flagButton; private Button nextButton; /** * 当前录入人员的编号 */ private long uId; /** * 当前工作作业的编号 */ private long pId; /** * 当前工作画像的编号 */ private long iId; /** * 当前工作画像的名称 */ private String iName; /** * 当前工作画像的文件 */ private File iFile; /** * 应用程序路径 */ private String iPath; /** * 是否是双重录入 */ private boolean dual; /** * 是否需要检查 */ private boolean hasc; /** * 是否需要校验 */ private boolean hasv; private Combo combo; public GFMInputerComposite(Shell parent, long uid, long pid) { super(parent, SWT.NONE); addDisposeListener(new DisposeListener() { public void widgetDisposed(final DisposeEvent e) { if(iId > 0){ DMPProject.Data.reset(iId, uId, DMPProject.Status.INPUTING); } } }); this.uId = uid; this.pId = pid; 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(); } }); 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) { flagImage(); } }); 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(); parent.setDefaultButton(nextButton); } @Override protected void checkSubclass() {} private void loadImage() { if (iFile != null && iFile.exists()) { iFile.delete(); } if (iId > 0) { // 获取文件 iFile = DMPProject.Data.getFile(iId); // 打开文件 launchProg(); } else { nextButton.setEnabled(false); loadButton.setEnabled(false); flagButton.setEnabled(false); } } private void flagImage() { DMPProject.Data.flag(iId); // 如果有文件,则先删除文件。 if (iFile != null && iFile.exists()) { iFile.delete(); } // 获取下一个文件 Map<String, Object> info = DMPProject.Data.next(pId, uId, DMPProject.Status.INPUTING, dual); if (info != null) { iId = (Long) info.get("id"); iName = (String)info.get("name"); getShell().setText("录入终端 v" + DMPApplication.VERSION + ": " + iName); // 获取文件 iFile = DMPProject.Data.getFile(iId); // 打开文件 launchProg(); } else { getShell().setText("录入终端 v" + DMPApplication.VERSION); nextButton.setEnabled(false); loadButton.setEnabled(false); flagButton.setEnabled(false); } } private void nextImage() { // 如果有文件,则先保存文件。 if (iFile != null && iFile.exists()) { saveImage(); iFile.delete(); } // 获取下一个文件 Map<String, Object> info = DMPProject.Data.next(pId, uId, DMPProject.Status.INPUTING, dual); if (info != null) { iId = (Long) info.get("id"); iName = (String)info.get("name"); // 获取文件 iFile = DMPProject.Data.getFile(iId); // 打开文件 launchProg(); } else { nextButton.setEnabled(false); loadButton.setEnabled(false); flagButton.setEnabled(false); } } private void saveImage() { try { FileInputStream fis = new FileInputStream(iFile); DMPProject.Data.setData(iId, fis, uId, DMPProject.Status.INPUTING, dual, hasc, 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); dual = (Boolean) project.get(DMPProject.Column.INPUT_MODE); hasc = (Boolean) project.get(DMPProject.Column.ENABLE_CHECK); 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.I, uId, pId, "com.cmspad.dmp.bundles.gfm"); // 初始化作业 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 + =
减小字号Ctrl + -
显示快捷键?