用友NC单据UI基本代码示例

本示例在用友NC57环境下调试通过

最近在做基于NC的二次开发,这种封闭的系统文档很少,一个简单的例子都不能找到帮助。

本示例的目的是为了让后来者少走我走过的弯路

package nc.ui.ic.generaltc;

import nc.ui.pub.ButtonObject;
import nc.ui.pub.ClientEnvironment;
import nc.ui.pub.ToftPanel;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillEditEvent;
import nc.ui.pub.bill.BillEditListener;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillListPanel;
import nc.ui.scm.pub.query.SCMQueryConditionDlg;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Dimension;

/**
 * NC5.7单据基础示例
 * @ClassName: ClientUI
 * @Description: TODO
 * @author s
 * @date 2013-4-9 下午2:22:21
 * BillEditListener  是按钮监听类
 * 实现BillEditListener,需实现bodyRowChange()、afterEdit()两个方法
 */
public class ClientUI extends ToftPanel implements BillEditListener {

	// 单据类型
	private BillCardPanel cpBill = null;
	
	// 客户端环境变量类
	private ClientEnvironment ce = getClientEnvironment();
	
	// 按钮查询,增加,修改,删除,保存,取消,打印,审核,弃审,关闭,打开.
	protected ButtonObject bnQuery = new ButtonObject("查询", "查询", 1, "查询");
	protected ButtonObject bnAdd = new ButtonObject("增加", "增加", 2, "增加");
	protected ButtonObject bnModify = new ButtonObject("修改", "修改", 3, "修改");
	protected ButtonObject bnDelete = new ButtonObject("删除", "删除", 4, "删除");
	protected ButtonObject bnSave = new ButtonObject("保存", "保存", 5, "保存");
	protected ButtonObject bnCancel = new ButtonObject("取消", "取消", 6, "取消");
	protected ButtonObject bnPrint = new ButtonObject("打印", "打印", 7, "打印");
	protected ButtonObject bnAudit = new ButtonObject("审核", "审核", 9, "审核");
	protected ButtonObject bnUnAudit = new ButtonObject("弃审", "弃审", 10, "弃审");
	protected ButtonObject bnClose = new ButtonObject("关闭", "关闭", 11, "关闭");
	protected ButtonObject bnOpen = new ButtonObject("打开", "打开", 12, "打开");
	
	protected ButtonObject[] bgMain = { bnQuery, bnAdd, bnModify, bnDelete,
			bnSave, bnCancel, bnPrint, bnAudit, bnUnAudit, bnClose, bnOpen };
	
	// 状态 有下列五种状态
	private int iStatus = 0;
	private int INIT = 0;
	private int NEW = 1;
	private int UPDATED = 2;
	private int DELETED = 3;
	private int SAVED = 4;
	
	private nc.vo.scm.pub.session.ClientLink m_cl=null;
	protected UIPanel conditionpanel = null;

	public ClientUI() {
		super();
		initialize();
	}

	/**
	 * 选中行触发该方法
	 */
	public void bodyRowChange(BillEditEvent arg0) {
		// TODO Auto-generated method stub
		// int isChangeRow = arg0.getRow();
	}

	public void afterEdit(BillEditEvent arg0) {
	}

	/**
	 * 界面初始化。
	 * @Title: initialize
	 * @Description: TODO
	 * @return void
	 * @throws
	 * 创建者:s
	 * 创建日期:2013-4-10
	 */
	private void initialize() {
		try {
			setName("TcUI");
			m_cl = new nc.vo.scm.pub.session.ClientLink(ClientEnvironment.getInstance());
			//INIT,NEW,UPDATED,DELETED,SAVED;
			iStatus = INIT;
			setBnStatus(iStatus);
			//bnOpen.setHint("测试!!!!!");
			// 加载按钮
			setButtons(bgMain);
			add(getBillCardPanel());
			// onQuery();
		} catch (Exception e) {
			 nc.vo.scm.pub.SCMEnv.out(e.getMessage());
			 JLabel msg = new JLabel(e.getMessage());
			 msg.setHorizontalAlignment(JLabel.CENTER);
			 add(msg);
		}
	}

	/**
	 * 设置单据窗体
	 * @Title: getBillCardPanel
	 * @Description: TODO
	 * @return BillCardPanel
	 * @throws
	 * 创建者:s
	 * 创建日期:2013-4-10
	 */
	private BillCardPanel getBillCardPanel() {
		if (cpBill == null) {
			try {
				cpBill = new BillCardPanel();
				/*
				 * 单据模板有两种常用加载方式
				 * 第一种是根据“单据模板编号”来加载
				 * 单据模板编号是模板在标准产品库中所保存的模板编号,在pub_billtemplet(单据模板主表)中的pk_billtemplet字段
				 * 可根据nodecode条件去pub_billtemplet表中查询
				 * 可用语句select pk_billtemplet from pub_billtemplet where nodecode='40081001'来查询
				 * nodecode是在“功能注册”时定义的节点“功能编码”,或称“节点编号”,见图1(单据类型管理)
				 */
				//cpBill.loadTemplet("0001AA1000000004OJWO");
				/*
				 * 第二种方式是使用cpBill.loadTemplet(strBillType, strBusiType, strOperator, strCorp)方法加载
				 * strBillType是单据模板在标准产品库中所保存的模板类型,在pub_billtemplet(单据模板主表)中的pk_billtypecode字段
				 * 可根据nodecode条件去pub_billtemplet表中查询
				 * 可用语句select pk_billtypecode from pub_billtemplet where nodecode='40081001'来查询
				 * strBusiType是业务类型,可设为null
				 * strOperator是操作者,使用ClientEnvironment.getUser().getPrimaryKey()取得环境用户参数
				 * strCorp是公司参数,使用ClientEnvironment.getCorporation().getPk_corp()取得环境公司参数
				 */
				cpBill.loadTemplet("40081001", null, ce.getUser().getPrimaryKey(), ce.getCorporation().getPk_corp());
				//设置单据体表体菜单是否显示
				cpBill.setBodyMenuShow(false);
				//添加监听
				cpBill.addEditListener(this);

			} catch (java.lang.Throwable ivjExc) {
			}
		}
		return cpBill;
	}
	/**
	 * 
	 * @Title: getConditionPanel
	 * @Description: TODO
	 * @return UIPanel
	 * @throws
	 * 创建者:s
	 * 创建日期:2013-4-9
	 */
	protected UIPanel getConditionPanel() {
		if (conditionpanel == null) {
			conditionpanel = new UIPanel();
			conditionpanel.setName("UIPanel");
			conditionpanel.setLayout(new java.awt.GridLayout(2, 6, 0, 1));
			conditionpanel.setMaximumSize(new Dimension(550, 40));
			conditionpanel.setPreferredSize(new Dimension(550, 40));
			conditionpanel.setMinimumSize(new Dimension(550, 1));
		}
		return conditionpanel;
	}
	
	@Override
	public String getTitle() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onButtonClicked(ButtonObject arg0) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 设置按钮状态。
	 * @Title: setBnStatus
	 * @Description: TODO
	 * @param status
	 * @return void
	 * @throws
	 * 创建者:s
	 * 创建日期:2013-4-10
	 */
	public void setBnStatus(int status) {
		//初始、删除、保存状态
		if (status == INIT || status == DELETED || status == SAVED) {
			bnQuery.setEnabled(true);
			bnAdd.setEnabled(true);
			bnModify.setEnabled(true);
			bnSave.setEnabled(false);
			bnCancel.setEnabled(false);
			bnDelete.setEnabled(true);
			//	bnModify.setEnabled(false);
		}
		//增加、修改状态
		else if (status == NEW || status == UPDATED) {
			bnQuery.setEnabled(false);
			bnAdd.setEnabled(false);
			bnSave.setEnabled(true);
			bnCancel.setEnabled(true);
			bnDelete.setEnabled(false);
			bnModify.setEnabled(false);
		}
			//bnPrint.setEnabled(false);
		updateButtons();
	}
}

图1:单据类型管理界面


你可能感兴趣的:(ERP开发)