用友NC63界面新增按钮实现方法(转)

原文地址:http://blog.csdn.net/qq_32553271/article/details/65644443

NC开发最基本的添加按钮并实现按钮事件业务逻辑处理,下面写一个例子介绍该过程的实现方法。

拿物流执行模块作为例子,在计量单维护界面增加两个按钮“A杆”“B杆”,单击这两个按钮,分别控制A和B道闸栏杆起降。

第一步:

             找到该页面的配置文件。打开“应用管理平台”–“开发配置工具”–“功能注册”节点,找到页面,查看参数注册,查看配置文件

第二步:

           在xml中添加两个按钮的配置(红颜色标记),如下:
          
          <!– 汽运计量模板——按钮 –>
          <beans default-lazy-init=”false”>
              <bean id=”actions” class=”nc.ui.mmgp.uif2.Container.MMGPActionList”>
                  <constructor-arg>
                     <list>
                          <!– <ref bean=”simulateAction” /> –>
                          <ref bean=”addAction” />
                          <ref bean=”nullaction” />
                          <ref bean=”refreshAction” />
                          <ref bean=”nullaction” />
                          <ref bean=”fillPrintAction” />                
                          <!– <ref bean=”limitedTareUpdateAction” /> –>
                          <ref bean=”printActionGroup” />
                          <ref bean=”nullaction” />
                          <ref bean=”nullaction” />
                          <ref bean=”Railing1Action”/>
                          <ref bean=”nullaction” />
                          <ref bean=”Railing2Action”/>
                      </list>
                  </constructor-arg>
              </bean>

              <!– 配置道闸栏杆起降的两个按钮 –>    
              <bean id=”Railing1Action” class=”nc.ui.levmmeampoundbill.poundbill.action.Railing1Action”/>
              <bean id=”Railing2Action” class=”nc.ui.levmmeampoundbill.poundbill.action.Railing2Action”/>
   
第三步:创建Railing1Action和Railing2Action类f继承父类NCAction

1、Railing1Action类

            package nc.ui.levmmeampoundbill.poundbill.action;

           import Java.awt.event.ActionEvent;
           import java.util.ArrayList;
           import Automation.BDaq.DaqException;
           Automation.BDaq.DeviceInformation;
           import Automation.BDaq.DeviceTreeNode;
           import Automation.BDaq.InstantDoCtrl;
           import nc.ui.uif2.NCAction;
           import nc.vo.pub.BusinessException;
           /**
            * PCI-1761板卡控制
            *
            * @author dingxm
            *
            */
           public class Railing1Action extends NCAction {
              // 1、定义端口、设备名称
               private static int channel = 0;// 继电器通道,默认通道为0
               private static String device = “PCI-1761,BID#0”; // 设备描述
               // private static int deviceNumber = 2;// 设备号
               private static InstantDoCtrl instantDoCtrl = null;
               private static final long serialVersionUID = 5566110189672221376L;


               @Override
               public void setCode(String code) {
                   super.setCode(“Railing1”);
               }

               public Railing1Action() {
                   // super.setCode(“dzupordown1”);
                   super.setCode(“Railing2”);
                   super.setBtnName(“A杆”);
               }

               @Override
               public void doAction(ActionEvent arg0) throws Exception {

                   instantDoCtrl = new InstantDoCtrl();
                   // 3、打开设备
                   try {
                       instantDoCtrl.setSelectedDevice(new DeviceInformation(device));
                   } catch (DaqException e) {
                       e.printStackTrace();
                   }

                   if (instantDoCtrl.getState().toInt() == 0) {// 判断设备加载初始化成功
                       byte status = RailingActionCommon.readStatusFromPCI1761(
                               instantDoCtrl, channel);
                       byte value = 0;
                       if (status == 0) {
                           value = 1;
                       }
                       if (status == 1) {
                           value = 0;
                       }
                       if (status == 2) {
                           value = 3;
                       }
                       if (status == 3) {
                           value = 2;
                       }
                       RailingActionCommon.writeToPCI1761(instantDoCtrl, channel, value);
                   } else {
                       // 提示加载设备初始化失败
                       throw new BusinessException(“PCI-1761板卡初始化错误,请检查板卡名称配置”);
                   }
               }
           }


2、Railing2Action类

           package nc.ui.levmmeampoundbill.poundbill.action;

           import java.awt.event.ActionEvent;
           import Automation.BDaq.DaqException;
           import Automation.BDaq.DeviceInformation;
           import Automation.BDaq.InstantDoCtrl;
           import nc.ui.uif2.NCAction;
           import nc.vo.pub.BusinessException;

           /**
            * PCI-1761板卡控制
            *
            * @author dingxm
            *
            */
           public class Railing2Action extends NCAction {
               // 1、定义端口、设备名称
               private int channel = 0;// 继电器通道,默认通道为0
               private static String device = “PCI-1761,BID#0”;// “DemoDevice,BID#0”;//
                                                    // 设备描述
               // private static int deviceNumber = 2;// 设备号
               private static InstantDoCtrl instantDoCtrl = null;

               private static final long serialVersionUID = 5566110189672221376L;

               @Override
               public void setCode(String code) {
                   super.setCode(“Railing2”);
               }

               public Railing2Action() {
                   // super.setCode(“dzupordown2”);
                   super.setCode(“Railing2”);
                   super.setBtnName(“B杆”);
               }

               @Override
               public void doAction(ActionEvent arg0) throws Exception {

                   // 2、初始化InstantDoCtrl
                   instantDoCtrl = new InstantDoCtrl();
                   // 3、打开设备
                   try {
                       instantDoCtrl.setSelectedDevice(new DeviceInformation(device));
                   } catch (DaqException e) {
                       e.printStackTrace();
                   }

                   if (instantDoCtrl.getState().toInt() == 0) {// 判断设备加载初始化成功
                       byte status = RailingActionCommon.readStatusFromPCI1761(instantDoCtrl, channel);
                       byte value = 0;
                       if (status == 0) {
                           value = 2;
                       }
                       if (status == 1) {
                           value = 3;
                       }
                       if (status == 2) {
                           value = 0;
                       }
                       if (status == 3) {
                           value = 1;
                       }
                       RailingActionCommon.writeToPCI1761(instantDoCtrl, channel, value);
                   } else {
                       // 提示加载设备初始化失败
                       throw new BusinessException(“PCI-1761板卡初始化错误,请检查板卡名称配置”);
                   }
               }
           }


工具类:RailingActionCommon类         

           package nc.ui.levmmeampoundbill.poundbill.action;

           import Automation.BDaq.ByteByRef;
           import Automation.BDaq.ErrorCode;
           import Automation.BDaq.InstantDoCtrl;
           /**
            *
            * @author dingxiaomin
            *
            */
           public class RailingActionCommon {
               /**
                *
                * @param channel通道号
                * @param device设备描述
                * @param portData写入数据
                * @return返回写入成功与否
                */
               public static boolean writeToPCI1761(InstantDoCtrl instantDoCtrl, int channel, byte portData) {

                   boolean b = false;
                   ErrorCode errCode;
                   // 4、写入数据
                   errCode = instantDoCtrl.Write(channel, portData);
                   if (“Success”.equals(errCode.toString())) {// 写入成功返回true,其他均返回false
                      b = true;
                   }
                   return b;
               }

               /**
                *
                * @param channel通道号
                * @param device设备描述
                * @return返回该通道该设备读取的值
                *
                */
               public static byte readStatusFromPCI1761(InstantDoCtrl instantDoCtrl,int channel) {
                   // ErrorCode errCode;
                   ByteByRef portData = new ByteByRef();
                   // 4、读取数据
                   // errCode =
                   instantDoCtrl.Read(channel, portData);// 读取
                   return portData.value;
               }
           }

运行界面如下,到这一步已经显示出来两个按钮:

到上一步骤,虽然显示出来了两个按钮,按钮的doAction方法已经写完,但界面点击该按钮并未触发事件,还缺少下面一步骤:

在功能注册界面增加按钮配置:

到这一步,添加按钮的操作已经全部完成。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值