单据报表增加保存按钮
📣1. 需求
新建一张要存储保存数据的后台把,查出当月数据以后,可以点击保存按钮将当前月份的数据保存到后台表中。如果后台表中没有当前月份的数据,则直接保存到后台表中;如果后台表中有当前月份的数据,则前台会提示“
当前月份数据以存在,保存将会删除原版本数据,是否保存!
”,若点击是
,则删除后台表中当前月份的数据,然后将前台报表中当前月份的数据保存到后台表;若点击否
,则取消保存。
📣2. 实现
✨2.1按钮类
package nc.ui.jych.yztz.ace.action;import java.awt.event.ActionEvent;
import java.util.List;import nc.bs.framework.common.NCLocator;
import nc.itf.jych.IYztzMaintain;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pubapp.uif2app.model.BatchBillTableModel;
import nc.ui.pubapp.uif2app.view.ShowUpableBatchBillTable;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;
import nc.ui.uif2.NCAction;
import nc.vo.jych.util.SqlBuilder;
import nc.vo.jych.yztz.YztzVO;public class SaveAction extends NCAction{private static final long serialVersionUID = 1L;private BatchBillTableModel model;private ShowUpableBatchBillTable list;protected ShowUpableBillForm editor;public SaveAction() {setBtnName("保存");setCode("saveAction");}@SuppressWarnings("unchecked")@Overridepublic void doAction(ActionEvent e) throws Exception {// 获取页面所有数据List<Object> yztzlist = getModel().getRows();SqlBuilder sqlname = new SqlBuilder();sqlname.append(" select * from zk_yztzdata where nvl(dr, 0) = 0 and kjqj = '"+yztzlist.toArray(new YztzVO[0])[0].getKjqj()+"' ");List<YztzVO> volist = (List<YztzVO>)getQueryService().executeQuery(sqlname.toString(), new BeanListProcessor(YztzVO.class));if(volist!=null && volist.size()>0 && MessageDialog.showOkCancelDlg(list, "提示", "当前月份数据以存在,保存将会删除原版本数据,是否保存!") == UIDialog.ID_CANCEL){return;}if(yztzlist!= null && yztzlist.size() > 0){getService().save(yztzlist.toArray(new YztzVO[0]));MessageDialog.showHintDlg(null, "提示", "保存成功");}}public BatchBillTableModel getModel() {return model;}public void setModel(BatchBillTableModel model) {this.model = model;}public ShowUpableBatchBillTable getList() {return list;}public void setList(ShowUpableBatchBillTable list) {this.list = list;}public ShowUpableBillForm getEditor() {return editor;}public void setEditor(ShowUpableBillForm editor) {this.editor = editor;}//前端查sql要用到的方法private IUAPQueryBS queryservice;private IUAPQueryBS getQueryService() {if (queryservice == null) {queryservice = NCLocator.getInstance().lookup(IUAPQueryBS.class);}return queryservice;}private IYztzMaintain service;private IYztzMaintain getService(){if(service == null){service = NCLocator.getInstance().lookup(IYztzMaintain.class);}return service;}
}
✨2.2 保存接口类
package nc.impl.jych;import java.util.List;import nc.bs.dao.BaseDAO;
import nc.itf.jych.IYztzMaintain;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.jych.util.SqlBuilder;
import nc.vo.jych.yztz.YztzQueryParam;
import nc.vo.jych.yztz.YztzVO;public class YztzMaintainImpl implements IYztzMaintain{@SuppressWarnings("unchecked")@Overridepublic YztzVO[] save(YztzVO[] vos) throws Exception {getDao().deleteByClause(YztzVO.class, " kjqj = '"+vos[0].getKjqj()+"' ");getDao().insertVOArray(vos);SqlBuilder sqlname = new SqlBuilder();sqlname.append(" select * from zk_yztzdata where nvl(dr, 0) = 0 and kjqj = '"+vos[0].getKjqj()+"' ");sqlname.append(" order by rowno ");List<YztzVO> volist = (List<YztzVO>)getDao().executeQuery(sqlname.toString(), new BeanListProcessor(YztzVO.class));if(volist != null && volist.size() > 0){return volist.toArray(new YztzVO[0]);}return null;}private BaseDAO dao;private BaseDAO getDao(){if(dao == null){dao = new BaseDAO();}return dao;}}