NC65增加导入导出按钮

在client端action包中创建exportaction和importaction Java类,在action同级创建一个dialog包用来存放exportdialog和filedialog Java类

exportaction.java

package nc.ui.jygyl.xmqddzb.ace.action;

import java.awt.event.ActionEvent;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.ui.jygyl.yzxzxxb.ace.dialog.ExportDialog;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.ShowStatusBarMsgUtil;
import nc.vo.jygyl.tool.NullValueUtils;
import nc.vo.jygyl.xmqddzb.AggXmqddzbVO;
import nc.vo.jygyl.xmqddzb.XmqddzbBVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
 * 业主征询信息表导出
 * @author wf
 * @date 2023-05-29
 */
public class ExportAction extends NCAction{

	private static final long serialVersionUID = -2288549251908687419L;
	private BillManageModel model;
	protected ShowUpableBillForm editor;

	public ExportAction() {
		setBtnName("导出");
		setCode("exportAction");
	}

	@Override
	public void doAction(ActionEvent arg0) throws Exception {
		// TODO 自动生成的方法存根
		ExportDialog fileDlg = new ExportDialog();
		if (fileDlg.show()) {
			// 得到导出的EXCEL文件路径
			String filepath = fileDlg.getFilePath();
			if (filepath == null) {
				ShowStatusBarMsgUtil.showErrorMsg("提示", "请选择导出路径!", getModel()
						.getContext());// 最下面红色显示
				return;
			}
			try {
				export(filepath);
			} catch (Exception e) {
				ExceptionUtils.wrappBusinessException("程序出错:" + e.getMessage());
			}
		}
		ShowStatusBarMsgUtil.showStatusBarMsg("导出模板成功!", getModel()
				.getContext());

	}

	public void export(String filepath) throws BusinessException {

		XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
		SXSSFWorkbook wb = new SXSSFWorkbook(xssfWorkbook, 100);
		// 创建工作表
		SXSSFSheet wbSheet = (SXSSFSheet) wb.createSheet(getExcelSheetName());
		// 设置默认行宽
		wbSheet.setDefaultColumnWidth(10);
		// 标题样式(加粗,垂直居中)
		XSSFCellStyle cellStyle = (XSSFCellStyle) wb.createCellStyle();
		cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);// 水平居中
		XSSFFont fontStyle = (XSSFFont) wb.createFont();
		fontStyle.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
		fontStyle.setFontHeightInPoints((short) 16); // 设置标题字体大小
		cellStyle.setFont(fontStyle);
		// 设置表头样式,表头居中
		XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
		// 设置单元格样式
		style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
		style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
		// 设置字体
		XSSFFont font = (XSSFFont) wb.createFont();
		font.setFontHeightInPoints((short) 9);
		style.setFont(font);
		// 在第1行创建rows
		SXSSFRow row = (SXSSFRow) wbSheet.createRow((int) 0);
		// 设置列头元素
		SXSSFCell cellHead = null;
		for (int i = 0; i < getExportFieldsName().length; i++) {
			cellHead = (SXSSFCell) row.createCell(i);
			cellHead.setCellValue(getExportFieldsName()[i]);
			cellHead.setCellStyle(style);

		}
		// 获取页面所有数据
		//		AggXmqddzbVO aggvo = (AggXmqddzbVO) getModel().getSelectedData();
		Object[] objs=this.model.getSelectedOperaDatas();
		if (objs == null) {
			throw new BusinessException(" 未选择导出数据! ");
		}
		List<AggXmqddzbVO> aggvolist=new ArrayList<AggXmqddzbVO>();
		for (Object obj : objs) {
			//aggvo
			AggXmqddzbVO aggvo = (AggXmqddzbVO)obj;
			aggvolist.add(aggvo);
		}
		if (aggvolist != null && aggvolist.size() > 0) {
			for (int i = 0; i < aggvolist.size(); i++) {
				XmqddzbBVO[] bvos = (XmqddzbBVO[]) aggvolist.get(i).getChildren(XmqddzbBVO.class);
				if (bvos != null && bvos.length > 0) {
					for (int j = 0; j < bvos.length; j++) {
						// 在第2行创建rows
						SXSSFRow rows = (SXSSFRow) wbSheet.createRow(j+1);
						// 设置列头元素
						SXSSFCell cellHeads = null;
						// 写入数据内容
						String[] fieldsValue = new String[] {
								NullValueUtils.getNullStringValue(getCfwlbm(bvos[j].getCfwlbm())),
								NullValueUtils.getNullStringValue(bvos[j].getCfwlmc()),
								NullValueUtils.getNullStringValue(bvos[j].getCfgg()),
								NullValueUtils.getNullStringValue(bvos[j].getCfxh()),
								NullValueUtils.getNullStringValue(bvos[j].getPmwlbm()),
								NullValueUtils.getNullStringValue(bvos[j].getPmwlmc()),
								NullValueUtils.getNullStringValue(bvos[j].getPmgg()),
								NullValueUtils.getNullStringValue(bvos[j].getPmxh())
						};

						// 开始写入数据,l为列值
						for (int l = 0; l < fieldsValue.length; l++) {
							cellHeads = (SXSSFCell) rows.createCell(l);
							cellHeads.setCellValue(fieldsValue[l]);
							cellHeads.setCellStyle(style);

						}
					}
				}
				try {
					FileOutputStream fout = new FileOutputStream(filepath
							+ "\\项目清单对照表"
							+ new UFDate().toStdString().substring(0, 10) + ".xlsx");
					wb.write(fout);
					fout.close();
				} catch (Exception e) {
					// TODO 自动生成的 catch 块
					throw new BusinessException("生成excel出错:" + e.getMessage());
				}
			}
		}

	}

	private Object getCfwlbm(String cfwlbm) throws BusinessException {
		// TODO 自动生成的方法存根
		String sql = " select code from bd_material where isnull(dr,0) = 0 and pk_material = '"+cfwlbm+"' ";
		String code = NullValueUtils.getNullStringValue(getService().executeQuery(sql, new ColumnProcessor()));
		if (code != null && !"".equals(code)) {
			return code.toString();
		}
		return null;
	}


	private String[] getExportFieldsName() {
		return new String[] { "CF物料编码", "CF物料名称", "CF规格", "CF型号", "PM物料编码",
				"PM物料名称", "PM规格", "PM型号"};
	}

	private String getExcelSheetName() {
		String date = new UFDate().toString().substring(0, 10);
		return "项目清单对照表" + date;
	}

	public BillManageModel getModel() {
		return model;
	}
	public void setModel(BillManageModel model) {
		this.model = model;
		this.model.addAppEventListener(this);
	}
	public ShowUpableBillForm getEditor() {
		return editor;
	}
	public void setEditor(ShowUpableBillForm editor) {
		this.editor = editor;
	}
	private IUAPQueryBS service;
	private IUAPQueryBS getService() {
		if(service == null) {
			service = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		}
		return service;
	}
}

importaction.java

package nc.ui.jygyl.xmqddzb.ace.action;

import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.itf.jygyl.IXmqddzbMaintain;
import nc.ui.jygyl.yzxzxxb.ace.dialog.FileDialog;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;
import nc.ui.uif2.NCAction;
import nc.vo.jygyl.tool.NullValueUtils;
import nc.vo.jygyl.xmqddzb.AggXmqddzbVO;
import nc.vo.jygyl.xmqddzb.XmqddzbBVO;
import nc.vo.jygyl.xmqddzb.XmqddzbVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVOUtil;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.AppContext;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
 * 项目清单对照表导入
 * @author wf
 *
 */
public class ImportAction extends NCAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BillManageModel model;
	protected ShowUpableBillForm editor;
	public ImportAction() {
		// TODO 自动生成的构造函数存根

		setBtnName("导入");
		setCode("ImportAction");
	}
	@Override
	public void doAction(ActionEvent e) throws Exception {
		FileDialog fileDlg = new FileDialog();
		if(fileDlg.show()){

			//得到导入的EXCEL文件路径
			String filepath = fileDlg.getFilePath();
			if (filepath == null) {
				MessageDialog.showErrorDlg(null, "", "请选择文件");
				return;
			}
			try {
				List<AggXmqddzbVO> voslist = new ArrayList<AggXmqddzbVO>();
				InputStream input = null;
				XSSFWorkbook wb = null;
				try {
					input = new FileInputStream(filepath);
					wb = new XSSFWorkbook(input);
					XSSFSheet xssfSheet = wb.getSheetAt(0);
					if (xssfSheet == null) {
						throw new BusinessException("解析excel出错:未读取到页签!");
					}
					int totalRows = xssfSheet.getPhysicalNumberOfRows();// 行数
					int totalCells = xssfSheet.getRow(0).getLastCellNum();// 列数
					if (totalRows <= 0) {
						throw new BusinessException("Excel为空,请检查!");
					}

					//for (int i = 1; i < 2; i++) {	

					AggXmqddzbVO aggvo = new AggXmqddzbVO();

					XmqddzbVO vo = new XmqddzbVO();


					//创建时间
					vo.setDbilldate(NullValueUtils.getUFDateNullValue(xssfSheet.getRow(1).getCell(0).getStringCellValue()));
					//项目编号
					vo.setXmbh(NullValueUtils.getNullStringValue(xssfSheet.getRow(1).getCell(1).getStringCellValue()));
					vo.setVbillstatus(-1);
					//单据类型
					vo.setPk_billtype("QDDZ");
					//单据编码
					vo.setTranstypecode("QDDZ");
					//集团
					vo.setPk_group(AppContext.getInstance().getPkGroup());
					//组织
					vo.setPk_org("001");
					vo.setPk_org_v(vo.getPk_org());
					vo.setVbillstatus(-1);
					//制单时间
					vo.setCreationtime(new UFDateTime());
					//制单人
					vo.setCreator(AppContext.getInstance().getPkUser());
					vo.setStatus(VOStatus.NEW);
					aggvo.setParent(vo);
					SuperVOUtil.execFormulaWithVOs(new XmqddzbVO[]{vo}, new String[]{
							"xmbh->getcolvalue(bd_project,pk_project ,project_code,\""+vo.getXmbh()+"\")",
							"pk_org->getcolvalue(org_orgs,pk_org,code,\""+vo.getPk_org()+"\")",
					});
					List<XmqddzbBVO> bvolist = new ArrayList<XmqddzbBVO>();
					for (int z = 3; z < totalRows; z++) {
						XmqddzbBVO bvo = new XmqddzbBVO();
						//CF物料编码
						bvo.setCfwlbm(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(0).getStringCellValue()));
						//CF物料名称
						bvo.setCfwlmc(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(1).getStringCellValue()));
						//CF物料规格
						bvo.setCfgg(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(2).getStringCellValue()));
						//CF物料型号
						bvo.setCfxh(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(3).getStringCellValue()));
						//PM物料编码
						bvo.setPmwlbm(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(4).getStringCellValue()));
						//PM物料名称
						bvo.setPmwlmc(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(5).getStringCellValue()));
						//PM物料规格
						bvo.setPmgg(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(6).getStringCellValue()));
						//PM物料型号
						bvo.setPmxh(NullValueUtils.getNullStringValue(xssfSheet.getRow(z).getCell(7).getStringCellValue()));
						bvolist.add(bvo);
						aggvo.setChildren(XmqddzbBVO.class, bvolist.toArray(new XmqddzbBVO[bvolist.size()]));
						SuperVOUtil.execFormulaWithVOs(new XmqddzbBVO[]{bvo}, new String[]{
								"cfwlbm->getcolvalue(bd_material,pk_material,code,\""+bvo.getCfwlbm()+"\")",
						});
					}
					voslist.add(aggvo);

					//}

					AggXmqddzbVO[] vos = getService().insert(voslist.toArray(new AggXmqddzbVO[0]), voslist.toArray(new AggXmqddzbVO[0]));
					getModel().initModel(vos);
				} catch (Exception e1) {
					throw new BusinessException(e1.getMessage());
				} finally {
					try {
						if (input != null) {
							input.close();
						}
					} catch (IOException e1) {
					}
				}
			}catch (Exception e1) {
				e1.printStackTrace();
				MessageDialog.showErrorDlg(null, "", "导入失败," + e1.getMessage());
				return;
			}
			MessageDialog.showHintDlg(null, "", "导入成功!");

		}
	}

	private IXmqddzbMaintain service;

	private IXmqddzbMaintain getService() {
		if (service == null) {
			service = NCLocator.getInstance().lookup(
					IXmqddzbMaintain.class);
		}
		return service;
	}
	@Override
	public boolean isActionEnable() {
		return true;
	}
	public BillManageModel getModel() {
		return model;
	}
	public void setModel(BillManageModel model) {
		this.model = model;
		this.model.addAppEventListener(this);
	}
	public ShowUpableBillForm getEditor() {
		return editor;
	}
	public void setEditor(ShowUpableBillForm editor) {
		this.editor = editor;
	}
}

exportdialog.java

package nc.ui.jygyl.xmqddzb.ace.dialog;

import javax.swing.JFileChooser;

public class ExportDialog {
	JFileChooser jFileChooser = new JFileChooser();

	public ExportDialog() {
		super();
	}

	public boolean show() {
		jFileChooser.removeChoosableFileFilter(jFileChooser
				.getAcceptAllFileFilter());
		jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		return JFileChooser.APPROVE_OPTION == jFileChooser.showOpenDialog(null);
	}

	public String getFilePath() {
		return jFileChooser.getSelectedFile().getPath();
	}
}

filedialog.java

package nc.ui.jygyl.xmqddzb.ace.dialog;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
public class FileDialog {

	/**
	 * @describe:excel文件选择对话框
	 * @author:wf
	 * @date:2023-05-29
	 */
	JFileChooser jFileChooser = new JFileChooser(); 

	public FileDialog() {
		super();
	}

	public boolean show(){
		jFileChooser.removeChoosableFileFilter(jFileChooser.getAcceptAllFileFilter());
		jFileChooser.setFileFilter(new FileFilter() {
			public boolean accept(File f) {
				if(f.getName().endsWith(".xlsx")||f.isDirectory()){
					return true;
				}
				return false;
			}
			public String getDescription() {
				// TODO 自动生成方法存根
				return "所有文件(*.xlsx)";
			}
		});
		return JFileChooser.APPROVE_OPTION == jFileChooser.showOpenDialog(null);
	}

	public String getFilePath(){
		return jFileChooser.getSelectedFile().getPath();
	}

}

之后在xml中添加导入导出的按钮(如下位置,只在非编辑态下可见):

	<!-- 列表显示下的按钮 -->
	<bean id="actionsOfList" class="nc.ui.uif2.actions.StandAloneToftPanelActionContainer">
		<constructor-arg ref="billListView" />
		<property name="model" ref="bmModel" />
		<property name="actions">
			<list>
				<ref bean="addAction" />
				<ref bean="editAction" />
				<ref bean="deleteScriptAction" />
				<ref bean="defaultQueryAction" />
				<ref bean="copyAction" />
				<ref bean="separatorAction" />
				<ref bean="defaultRefreshAction" />
				<ref bean="separatorAction" />
				<ref bean="commitScriptAction" />
				<ref bean="unCommitScriptAction" />
				<ref bean="approveScriptAction" />
				<ref bean="uNApproveScriptAction" />
				<ref bean="separatorAction" />
				<ref bean="linkQueryAction" />
				<ref bean="separatorAction" />
				<ref bean="metaDataBasedPrintAction" />
				<ref bean="metaDataBasedPrintActiona" />
				<ref bean="outputAction" />
				<ref bean="separatorAction" />
				<ref bean="importAction" />
				<ref bean="exportAction" />
			</list>
		</property>
	</bean>
	
	<!-- 卡片显示下的按钮 -->
	<bean id="actionsOfCard" class="nc.ui.uif2.actions.StandAloneToftPanelActionContainer">
		<constructor-arg ref="billForm" />
		<property name="model" ref="bmModel" />
		<!-- 此处配置的Action浏览态始终可见 -->
		<property name="actions">
			<list>
				<ref bean="addAction" />
				<ref bean="editAction" />
				<ref bean="deleteScriptAction" />
				<ref bean="defaultQueryAction" />
				<ref bean="separatorAction" />
				<ref bean="copyAction" />
				<ref bean="cardRefreshAction" />
				<ref bean="separatorAction" />
				<ref bean="commitScriptAction" />
				<ref bean="unCommitScriptAction" />
				<ref bean="approveScriptAction" />
				<ref bean="uNApproveScriptAction" />
				<ref bean="separatorAction" />
				<ref bean="linkQueryAction" />
				<ref bean="separatorAction" />
				<ref bean="metaDataBasedPrintAction" />
				<ref bean="metaDataBasedPrintActiona" />
				<ref bean="outputAction" />
				<ref bean="separatorAction" />
				<ref bean="pFApproveStatusInfoAction" />
				<ref bean="separatorAction" />
				<ref bean="importAction" />
				<ref bean="exportAction" />
			</list>
		</property>
.
.
.
.
.
.
.
.
.
.
	<!--======= 动作:[newActions] [导入] ===========-->
	<bean id="importAction" class="nc.ui.jygyl.xmqddzb.ace.action.ImportAction">
		<property name="model"><ref bean="bmModel"/></property>
		<property name="editor"><ref bean="billForm"/></property>
		<property name="exceptionHandler"><ref bean="exceptionHandler" /></property>
	</bean>
	<!--======= 动作:[newActions] [导出] ===========-->
	<bean id="exportAction" class="nc.ui.jygyl.xmqddzb.ace.action.ExportAction">
		<property name="model"><ref bean="bmModel"/></property>
		<property name="editor"><ref bean="billForm"/></property>
		<property name="exceptionHandler"><ref bean="exceptionHandler" /></property>
	</bean>
	<!--分隔按钮-->
	<bean id="separatorAction" class="nc.funcnode.ui.action.SeparatorAction" />
    
	<bean id="exceptionHandler" class="nc.ui.uif2.DefaultExceptionHanler">
		<constructor-arg><ref bean="container"/></constructor-arg>
		<property name="context"><ref bean="context" /></property>
	</bean>
	
	<!-- 批量保存校验服务类 -->
</beans>

最后,登录客户端,动态建模平台→开发配置→功能注册中去修改其参数值:

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
信息交换平台 实施技术红皮书 NC-UAP 6.0 目 录 第一章 总体概述 1 1. 信息交换平台总体结构 1 2. 信息交换平台功能特点 1 3. 信息交换平台V50版新增功能 2 4. 信息交换平台V55版新增功能 3 5. 信息交换平台V60版新增功能 3 第二章 实施简介及相关注意点 4 1. 实施方法简介 4 外系统数据导入的一般步骤 4 信息交换平台服务器端文件目录结构 5 2. Servlet的URL地址参数与XML交换文档头属性的关系 6 3. 向NC系统发送数据方式 7 手动界面发送 7 后台预警发送 8 自定义程序发送 11 4. 回执及异常出错信息 12 回执格式 12 异常和错误编码 14 查询及回执格式样例 14 5 . 信息交换平台总体参数设置 23 外部系统默认帐套 24 单篇最大传输上限 24 导入过程是否记录中间文件 25 回执文件后台备份 25 回执和导出文件编码格式 25 单据导入规则设置 26 设置客户端IP范围 26 6. 单据流水号和单据并发控制 26 单据流水号的概念和作用 26 单据并发控制 27 7. 日志查看 27 8. 翻译器配置 30 第三章 单据交换规则定义 32 1. 校验文件全局配置 32 2. 表记录的配置 34 3. 字段属性项的配置 34 第四章 基于信息交换平台的单据集成开发 44 1. 注册单据相关信息 44 2. 生成&配置交换规则定义文件 45 3. 辅助信息项设置 48 4. 插件代码维护 49 第五章 单据集成示例 51 1. 问题描述 51 2. 设计 51 3. 具体开发指导 51 3.1 单据插件信息注册 51 3.2 单据转换规则定义 51 3.3 插件代码编写和部署 52 3.4 修改单据转换规则 52 3.5 手动加载测试 53 第六章 安全 54 1. 加密类编写 54 2. 加密类注册 56 第七章 扩展 57 第八章 JMS及大文件传输模式 59 1信息交换平台异步通信解决方案 59 1.1信息交换平台现状及存在的问题 59 1.2需求分析 59 1.3 JMS简介 60 1.3 JMS Client消息交互图 62 1.5解决方案 62 2.JMS传输模式 64 3. JMS Client For NC6.0 65 4 大文件传输模式 85 附录 86 1发送结果错误码 86 2 K系统自定义项目档案样本defdoc.xml 89 常见问题 90

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值