连续加班3月了,走得早的时候是晚上10点半,正好赶上末班公交车,走得晚的时候是凌晨3点 ,一般十点不走就是凌晨一点走。---所以,我要努力学知识,换家公司。
NC的打印模板其实功能很齐全,一个不会编程的人也可以按照他自己的意愿做出来一个打印模板,只是有时候,NC各种bug往往导致达不到效果。
项目中使用的是NC57 ,客户要求 在一个 如下图的单据中打印 出 图中 1 与2的数据 (1跟2的单据模板一致只是单据类型不一致)。
这点采用的实现方式是:将1中的vo 放入一个集合中 ,再将2中的VO放入这个集合中 。
接着 ,客户要求 将1中的码洋,实洋汇总 显示出来
此时采用的策略是 再放入2中的VO到集合前新建一个VO,将计算出来的合计值赋值到对应的字段,再将该VO追加到集合中
同样汇总2中的码洋实洋字段。
附关键代码:
if (intBtn == IXhfxButton.ZJSPRINT) {//转结算查询
.......
billvos.add(sumvo);
onPrintElse(billvos.toArray(new SellToSettlementBVO[0]));
return;
}
private void onPrintElse(SellToSettlementBVO[] bvos) throws Exception {
if (ctrl.getBillType().equals("TN2E")) {
nc.ui.pub.print.IDataSource dataSource = new MyListDataSource(bvos, "TN2EB");// 货源对账
// nc.ui.pub.print.IDataSource dataSource = new OwnerListDataSource("HN307030", checkbillui.getPanel2());//
nc.ui.pub.print.PrintEntry print = new nc.ui.pub.print.PrintEntry(null, dataSource);
print.setTemplateID("0001", "HN307040", null, null, null);
if (print.selectTemplate() == 1) {
print.preview();
}
}
}
/*
* @(#)MyListDataSource.java V55 2009-1-4 上午11:22:31
*
* ====================================================================
* Copyright (C) 1988-2009 UFIDA SOFTWARE CO., LTD. All Rights Reserved.
*
* http://www.ufida.com.cn
*
* This software is the proprietary information of UFIDA SOFTWARE CO., LTD.
* Use is subject to license terms.
*
*/
package nc.ui.hn.hn307050;
import java.util.HashMap;
import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.billtemplate.IBillTemplateQry;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.ui.bd.ref.AbstractRefModel;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillListData;
import nc.ui.pub.bill.IBillItem;
import nc.ui.pub.print.IDataSource;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDouble;
import nc.vo.scm.pub.SCMEnv;
import nc.vo.trade.pub.HYBillVO;
/**
* @description 处理单表、主子表的数据源
* @author <a href="mailto:linglijunmail@gmail.com"> llj </a>
* @date 2009-1-4 上午11:22:31
* @version V55
*/
public class MyListDataSource implements IDataSource {
private static final long serialVersionUID = -4110730226663239729L;
private SuperVO headvo;
private SuperVO[] bodyvos;
private HashMap<String, String> hmBodyItems = new HashMap<String, String>();
private HashMap<String, String> hmHeadItems = new HashMap<String, String>();
private int count = 1;
private String vbilltype;
public MyListDataSource(SuperVO[] headvos,String vbilltype) {
super();
this.vbilltype=vbilltype;
// headvo = headvos;
bodyvos = headvos;
getAllDataItemNames();
}
/*
* (non-Javadoc)
*
* @see nc.ui.pub.print.IDataSource#getAllDataItemExpress()
*/
public String[] getAllDataItemExpress() {
int headCount = 0;
int bodyCount = 0;
if (headvo != null) {
headCount = headvo.getAttributeNames().length;
}
if (bodyvos != null && bodyvos.length > 0) {
bodyCount = bodyvos[0].getAttributeNames().length;
}
int count = headCount + bodyCount;
String[] expfields = new String[count];
try {
String[] headItems = headvo.getAttributeNames();
for (int i = 0; i < headCount; i++) {
expfields[i] = "h_" + headItems[i];
}
if (bodyvos != null && bodyvos.length > 0) {
String[] bodyItems = bodyvos[0].getAttributeNames();
for (int j = 0; j < bodyCount; j++) {
expfields[j + headCount] = bodyItems[j];
}
}
} catch (Throwable e) {
e.printStackTrace();
SCMEnv.out("error at getAllDataItemExpress()");
}
return expfields;
}
/*
* (non-Javadoc)
*
* @see nc.ui.pub.print.IDataSource#getAllDataItemNames()
*/
public String[] getAllDataItemNames() {
int headCount = 0;
int bodyCount = 0;
if (headvo != null) {
headCount = headvo.getAttributeNames().length;
}
if (bodyvos != null && bodyvos.length > 0)
bodyCount = bodyvos[0].getAttributeNames().length;
int count = headCount + bodyCount;
String[] namefields = new String[count];
try {
String[] headItems = headvo.getAttributeNames();
for (int i = 0; i < headCount; i++) {
namefields[i] = headItems[i];
hmHeadItems.put(headItems[i], headItems[i]);
}
if (bodyvos != null && bodyvos.length > 0) {
String[] bodyItems = bodyvos[0].getAttributeNames();
for (int j = 0; j < bodyCount; j++) {
namefields[j + headCount] = bodyItems[j];
hmBodyItems.put(bodyItems[j], bodyItems[j]);
}
}
} catch (Throwable e) {
e.printStackTrace();
SCMEnv.out("error at getAllDataItemNames()");
}
return namefields;
}
/*
* (non-Javadoc)
*
* @see
* nc.ui.pub.print.IDataSource#getDependentItemExpressByExpress(java.lang
* .String)
*/
public String[] getDependentItemExpressByExpress(String itemExpress) {
return null;
}
/*
* (non-Javadoc)
*
* @see nc.ui.pub.print.IDataSource#getItemValuesByExpress(java.lang.String)
*/
// 根据表头表体vo来取数,如果是表头,直接取数;
// 如果是表体,循环将所有行的数据取出来
public String[] getItemValuesByExpress(String itemExpress) {
SCMEnv.out("开始第" + (count++) + "次执行本方法,解析字段: " + itemExpress);
if (itemExpress.startsWith("h_") || itemExpress.startsWith("t_")) {
String itemExpress2 = itemExpress.substring(2);
if (!hmHeadItems.containsKey(itemExpress2)) {
}
Object obj = null;
if(itemExpress2.equalsIgnoreCase("voperatorid")||itemExpress2.equalsIgnoreCase("vapproveid") ){
try {
obj=getValue(0,null,headvo,itemExpress2);
} catch (BusinessException e) {
nc.bs.logging.Logger.error(e);
e.printStackTrace();
}
}else{
obj = headvo.getAttributeValue(itemExpress2);
}
if (obj == null) {
SCMEnv.out("解析字段: " + itemExpress + "为空,直接返回");
return new String[]{""};
}
if (obj != null) {
if(obj instanceof UFDouble && !itemExpress2.equalsIgnoreCase("npackkindsnum")&& !itemExpress2.equalsIgnoreCase("npackcsnum")){
return new String[]{new UFDouble(((UFDouble)obj).doubleValue(),2).toString()};
}else if (obj instanceof UFDouble && (itemExpress2.equalsIgnoreCase("npackkindsnum") || itemExpress2.equalsIgnoreCase("npackcsnum"))){
return new String[]{new UFDouble(((UFDouble)obj).doubleValue(),0).toString()};
}else if(itemExpress2.equalsIgnoreCase("vbillstatus")){//单据状态
if(obj.toString().equals("1")){
return new String[]{"审核通过"};
}else if(obj.toString().equals("8")){
return new String[]{"自由态"};
}
}else if(itemExpress2.equalsIgnoreCase("iproducttype")){//业务分类
if(obj.toString().equals("3")){
return new String[]{"一般图书"};
}else if(obj.toString().equals("1")){
return new String[]{"教材"};
}else if(obj.toString().equals("2")){
return new String[]{"教辅"};
}else if(obj.toString().equals("4")){
return new String[]{"音像"};
}
}
else{
return new String[]{obj.toString()};
}
}
}
// }
else {
if (bodyvos == null || bodyvos.length == 0)
return null;
int rowCount = bodyvos.length;
String[] retStr = new String[rowCount];
if (!hmBodyItems.containsKey(itemExpress)) {
SCMEnv.out(itemExpress + " :不是表体VO字段,进入特殊处理");
}
for (int i = 0; i < rowCount; i++) {
Object obj ;
obj = bodyvos[i].getAttributeValue(itemExpress);
if(obj==null){
try {
obj=getValue(i,bodyvos[i],headvo,itemExpress);
} catch (BusinessException e) {
nc.bs.logging.Logger.error(e);
e.printStackTrace();
}
}
if (obj != null) {
if (obj instanceof UFBoolean) {
if(obj.toString().equalsIgnoreCase("true")){
retStr[i]="Y";
}else{
retStr[i]="N";
}
} else {
retStr[i] = obj.toString();
}
if(obj instanceof UFDouble && !itemExpress.equalsIgnoreCase("ncount")){
retStr[i]=new UFDouble(((UFDouble)obj).doubleValue(),2).toString();
}
if(obj instanceof UFDouble && itemExpress.equalsIgnoreCase("ncount")){
retStr[i]=new UFDouble(((UFDouble)obj).doubleValue(),0).toString();
}
} else
retStr[i] = "";
}
return retStr;
}
return null;
}
private String getValue(int i, SuperVO bodyvos2, SuperVO headvo,String itemExpress) throws BusinessException {
String valuedata=null;
IUAPQueryBS qryService = NCLocator.getInstance().lookup(IUAPQueryBS.class);
Object pk_billtemplet = qryService.executeQuery("select pk_billtemplet from pub_billtemplet where pk_billtypecode='"
+ vbilltype + "' and isnull(dr,0)=0", new ColumnProcessor());
IBillTemplateQry templetService = NCLocator.getInstance().lookup(IBillTemplateQry.class);
BillListData listdata=new BillListData(templetService.findTempletData(pk_billtemplet.toString()));
//表头
BillItem[] itemshead=listdata.getHeadItems();
for(BillItem item:itemshead){
if(item.getKey().equalsIgnoreCase(itemExpress)){
if(item.getDataType()==IBillItem.UFREF){//如果是参照,找到对应的参照,然后进行查询
valuedata = getValueName(headvo, itemExpress, qryService, item);
}
}
}
//表体
BillItem[] items=listdata.getBodyItems();
if(bodyvos!=null){
for(BillItem item:items){
if(item.getKey().equalsIgnoreCase(itemExpress)){
valuedata = getValueName(bodyvos2, itemExpress, qryService, item);
}
}
}
return valuedata;
}
protected String getValueName(SuperVO headvo, String itemExpress, IUAPQueryBS qryService, BillItem item) throws BusinessException {
String valuedata;
UIRefPane pane=(UIRefPane) item.getComponent();
AbstractRefModel refmodel=pane.getRefModel();
String valuedatetemp=null;
String pkfilename=null;
if(refmodel.getPkFieldCode().indexOf(".")>0){
pkfilename=refmodel.getPkFieldCode().substring(refmodel.getPkFieldCode().indexOf(".")+1);
}else{
pkfilename=refmodel.getPkFieldCode();
}
if(!item.getTableCode().equalsIgnoreCase("new") && item.getPos()==1){
valuedatetemp=(String) headvo.getAttributeValue(pkfilename);
}else{
valuedatetemp=(String) headvo.getAttributeValue(itemExpress);
}
String tablename=refmodel.getTableName();
String value=refmodel.getRefNameField();
String sqlquery="select "+value+" from "+tablename+ " where "+pkfilename +"= '"+valuedatetemp+"'";
valuedata=(String) qryService.executeQuery(sqlquery, new ColumnProcessor());
return valuedata;
}
/*
* (non-Javadoc)
*
* @see nc.ui.pub.print.IDataSource#getModuleName()
*/
public String getModuleName() {
return "HN307050";
}
/*
* (non-Javadoc)
*
* @see nc.ui.pub.print.IDataSource#isNumber(java.lang.String)
*/
public boolean isNumber(String itemExpress) {
// try {
// if (itemExpress.startsWith("h_")) {
// BillItem item = m_listpanel.getHeadItem(itemExpress.substring(2));
// if (item == null)
// return false;
// if (item.getDataType() == 1 || item.getDataType() == 2) {
// return true;
// }
// } else if (itemExpress.startsWith("t_")) {
// BillItem item = m_listpanel.getBodyItem(itemExpress.substring(2));
// if (item == null)
// return false;
// if (item.getDataType() == 1 || item.getDataType() == 2) {
// return true;
// }
// } else {
//
// BillItem item = m_listpanel.getBodyItem(itemExpress);
// if (item == null) {
// return false;
// } else if (item.getDataType() == 1 || item.getDataType() == 2) {
// return true;
// }
// }
// } catch (Throwable e) {
// e.printStackTrace();
// SCMEnv.out("error at isNumber()");
// return false;
// }
return false;
}
// private ProcRegister getRegister() {
// return ProcRegister.getInstance();
// }
}