NC65常用案例

360 篇文章 104 订阅

1、隐藏字段

//表体隐藏
BillData bs =getBillCardPanel().getBillData();
BillItem[] items =bs.getBillModel().getBodyItems();
for (int i = 0; i <items.length; i++) {
    items[i].setShow(false);
}
getBillCardPanel().setBillData(bs);
//表头隐藏
billCardPanel.getHeadItem("aaa").getComponent().setVisible(false); 
 
billCardPanel.getHeadItem("aaa").getCaptionLabel().setText("");

2、代码执行公式

//表头
getBillCardPanel().execHeadLoadFormulas();
//表体
getBillCardPanel().getBillModel().execLoadFormula();
//表体某行、某个字段执行
getBillCardPanel().execBodyFormula(i,"pk_supdoc");
 
// 列表执行 案例
String[] strs = new String[8];
String pk_wuliao_pk_measdoc_strFomula = "pk_wuliao.pk_measdoc->getcolvalue(bd_material,pk_measdoc,pk_material,pk_wuliao);";
                String pk_wuliao_pk_marbasclass_strFomula = "pk_wuliao.pk_marbasclass->getcolvalue(bd_material,pk_marbasclass,pk_material,pk_wuliao);";
                String pk_wuliao_flname_strFomula = "pk_wuliao.pk_marbasclass.name->getcolvalue(bd_marbasclass,name,pk_marbasclass,pk_wuliao.pk_marbasclass);";
                String pk_wuliao_dwname_strFomula = "pk_wuliao.pk_measdoc.name->getcolvalue(bd_measdoc,name,pk_measdoc,pk_wuliao.pk_measdoc);";
                String pk_wuliao_name_strFomula = "pk_wuliao.name->getcolvalue(bd_material,name,pk_material,pk_wuliao);";
                String pk_wuliao_materialtype_strFomula = "pk_wuliao.materialtype->getcolvalue(bd_material,materialtype,pk_material,pk_wuliao);";
                String pk_wuliao_materialspec_strFomula = "pk_wuliao.materialspec->getcolvalue(bd_material,materialspec,pk_material,pk_wuliao);";
                String pk_wuliao_strFomula = "pk_wuliao->getcolvalue(bd_material,code,pk_material,pk_wuliao);";
                strs[0]=pk_wuliao_pk_marbasclass_strFomula;
                strs[1]=pk_wuliao_pk_measdoc_strFomula;
                strs[2]=pk_wuliao_flname_strFomula;
                strs[3]=pk_wuliao_dwname_strFomula;
                strs[4]=pk_wuliao_name_strFomula;
                strs[5]=pk_wuliao_materialtype_strFomula;
                strs[6]=pk_wuliao_materialspec_strFomula;
                strs[7]=pk_wuliao_strFomula;
                getbillListPanel().getBodyBillModel().execFormulas(strs);

3、字段下拉

getBillCardWrapper().initHeadComboBox("wlname",new String[]{"A","B","C"}, true);

4、JdbcSession

JdbcSession session = null;
session = PersistenceManager.getInstance().getJdbcSession();
session =JdbcSessionUtil.createJdbcSession();
 
 
 
private void testPersistenceManager() {
        int resultSize = 0;
        PersistenceManager sessionManager = null;
        try {
            // 开始JDBC会话
            sessionManager = PersistenceManager.getInstance("design");
            JdbcSession session = sessionManager.getJdbcSession();
            String sql = "select * from org_corp where code = ?"; 
            SQLParameter param = new SQLParameter(); // 构造参数对象
            param.addParam("101"); // 添加参数           
            ArrayList list = (ArrayList) session.executeQuery(sql, param,
                    new BeanListProcessor(CorpVO.class));
            resultSize = list.size();
            for (int i = 0; i < resultSize; i++) {
                CorpVO temp = (CorpVO) list.get(i);
                System.out.println(temp.getUnitcode());
                System.out.println(temp.getUnitname());
            }
        } catch (DbException e) {
            e.printStackTrace();
        } finally {
            if (sessionManager != null) {
                sessionManager.release(); // 关闭和释放连接会话
            }
        }
    }

5、参照相关

1.表头参照多选取值
 
((UIRefPane)billCardPanel.getHeadItem("aaa").getComponent()).getRefModel().getPkValues();
 
2.动态指定参照类
 
((UIRefPane)(getBillCardPanelWrapper().getBillCardPanel().getHeadItem("字段").getComponent())).setRefModel(参照类.class);
 
3.设置参照是否支持多选
 
((UIRefPane)editor.getBillCardPanel().getHeadItem("aaa").getComponent()).setMultiSelectedEnabled(true);
 
4.判断是否参照类型:
 
Object obj =((UIRefPane)getBillCardPanel().getHeadItem("").getComponent()).getRefModel();

6、 下拉去掉空白选项

单据模板设置必输即可

7、获取表体所有页签名

getBillCardPanel().getBillData().getBodyTableCodes();

8、取得某个页签上的vo

BillModel tempmodel = getEditor().getBillCardPanel().getBillModel("id_oadjtb_d");
OadjtbDVO[] dvos = (OadjtbDVO[]) tempmodel.getBodyValueVOs(OadjtbDVO.class.getName());
if(dvos!=null&&dvos.length>0)
{
 
}
 
ZzyjhBVO[] yjhbvos = (ZzyjhBVO[]) getEditor().getBillCardPanel().getBillModel().getBodyValueVOs(ZzyjhBVO.class.getName());
 
 
 
AggZzyjhHVO aggvo = (AggZzyjhHVO) getEditor().getBillCardPanel().getBillValueVO(AggZzyjhHVO.class.getName(),ZzyjhHVO.class.getName(),ZzyjhBVO.class.getName());

9、单据状态栏 —>输出消息

ShowStatusBarMsgUtil.showStatusBarMsg("执行成功!", model.getContext());

10、获取当前时间 当前年 当前月 当前集团 当前公司

CurTime.getCurrentTimeStampString();
 
//NC5X 
UFDate today = ClientEnvironment.getInstance().getDate();
String pk_corp = ClientEnvironment.getInstance().getCorporation().getPrimaryKey();
UFDate today = ClientEnvironment.getInstance().getBusinessDate();
String dDate = today.toString();
String cyear = ""+today.getYear();
String cmonth = today.getStrMonth();
 
 
//NC6X
String user = this.model.getContext().getPk_loginUser();// 当前登录用户
String pk_group = this.model.getContext().getPk_group();//当前登录集团
UFDate today = AppContext.getInstance().getBusiDate();
String pk_user = AppContext.getInstance().getPkUser();
String dDate = today.toString();
String cyear = ""+today.getYear();
String cmonth = today.getStrMonth();

11、UFDouble 保留2位有效数字

new UFDouble().setScale(2,UFDouble.ROUND_HALF_UP);

12、前台查询 即Client端

//1
IUAPQueryBS iquery = (IUAPQueryBS)NCLocator.getInstance().lookup(IUAPQueryBS.class);
ArrayList list = null;
String sql =" select pk_dept from bd_psnjob where ismainjob ='Y' and pk_psndoc ='"+pk_psndoc+"' and dr = 0 ";
list = (ArrayList) iquery.executeQuery(sql, new ArrayListProcessor());
if(list!=null&&list.size()>0&&list.get(0)!=null)
{
 Object[] obj =  (Object[]) list.get(0);
 if(obj!=null&&obj[0].toString().length()>0)
 {
     String pk_dept = obj[0].toString();
     e.getBillCardPanel().setHeadItem("pk_dept", pk_dept);
 }
}
 
//2
PsnjobVO[] vo = (PsnjobVO[]) HYPubBO_Client.queryByCondition(PsnjobVO.class,"ismainjob ='Y' and pk_psndoc ='"+pk_psndoc+"' and dr = 0 ");
if(vo!=null&&vo[0]!=null)
{
    String pk_dept = vo[0].getPk_dept();
    e.getBillCardPanel().setHeadItem("pk_dept", pk_dept);
}
 
 
//3
if(QwDdkhbHVO.CEMPLOYEEID.equals(e.getKey())){
    String cemployeeid = (String) e.getBillCardPanel().getHeadItem(QwDdkhbHVO.CEMPLOYEEID).getValueObject();
    String pk_dept = null;
    try {
        pk_dept = (String) HYPubBO_Client.findColValue("bd_psnjob", "pk_dept", "pk_psndoc='"+cemployeeid+"'");
         e.getBillCardPanel().setHeadItem(QwDdkhbHVO.PK_DEPT, pk_dept);
    } catch (UifException e1) {
        // TODO 自动生成的 catch 块
        e1.printStackTrace();
    }
    
}

13、字段 编辑态不可改,新增态可改

在EditAction中重载doAction方法中加入如下代码

BillItem txtCode = cardPanel.getHeadItem(CODE);//(获取字段控件)
txtCode.setEdit(true);//(设置编辑态可见,这个不影响控件可编辑性。这名字容易误导,被它还惨了。)
txtCode.setEnabled(false);//(设置可编辑,是否可编辑要设置这个。)

14、自定义参照

1)自定义一个RefModel继承自AbstractRefModel。
2)手动在bd_refinfo中插入一条数据refclass对应自定义的refmodel全路径。
3)在refmodel的vo元数据bmf参照中设置参照。(一般文档里都不说这一步,导致元数据引用时出不来参照。)
4)其他元数据ref时就可以出来来参照了
15、编辑时 切换某个页签

e.getBillCardPanel().getBodyTabbedPane().setSelectedIndex(0);

16、获取某个页签下的总行数与值

int rowb = e.getBillCardPanel().getRowCount();
for (int i = 0; i < rowb; i++) 
{
    Object temp = e.getBillCardPanel().getBodyValueAt(i,"字段名");
}

17、JAVA 连接数据库

// 创建一个Driver
private static String driver="oracle.jdbc.driver.OracleDriver";
// 创建一个url
private static String url=null;
// 创建一个数据库用户名
private static String orclcode=null;
// 创建一个数据库密码
private static String orclps=null;
// 创建一个数据库连接
Connection connection = null;
// 创建预编译语句对象,一般都是用这个而不用Statement
PreparedStatement pstm = null;
// 创建一个结果集对象
ResultSet rs = null;
 
//构造方法
public aa()
{
     url      = "jdbc:oracle:thin:@127.0.0.1/orcl";
     orclcode = "NC650902CS";
     orclps   = "NC650902CS";
}
 
 
    
static {  
   try {  
        Class.forName(driver);  
    } catch (ClassNotFoundException e) {  
        e.printStackTrace();  
    }  
}  
  
//获得Connection 
public static Connection getConnection() {  
    Connection conn = null;  
     try {  
         conn = DriverManager.getConnection(url, orclcode, orclps);  
     } catch (SQLException e) {  
         e.printStackTrace();  
     }  
    return conn;  
} 
 
 //查询
 public Boolean IsExitsUser(String usercode)
 {
       Boolean bol = true;
       connection = getConnection();  
    String sql = " select zw from fdgyl_userzw  where 1 = 1 and dr = 0  and code =?";  
    try {
        pstm = connection.prepareStatement(sql);
        pstm.setString(1, usercode);
        rs = pstm.executeQuery();
        while (rs.next()){
              this.blb = rs.getBlob("zw");
              if(blb==null)
              {
                  bol = false;
                  return bol;
              }                
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    ReleaseResource();
    return bol;
}
//更新 插入
public int insertUserToOracleBytes()
{
    connection = getConnection();  
    int res = 0;
    String sql = " update fdgyl_userzw set zw=? where code =?  and dr = 0  ";  
    try {
        pstm =connection.prepareStatement(sql);
        pstm.setBytes(1,lastRegTemp);
        pstm.setString(2, getUsercode());           
        pstm.executeUpdate();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    ReleaseResource();
    return res;
}
 
/**
 * 释放资源
 */
public void ReleaseResource() {
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    if (pstm != null) {
        try {
            pstm.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    if (connection != null) {
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

18、后台用BaseDao查询 即private端

public String getParameters(String code) throws Exception {
    BaseDAO dao = new BaseDAO(dsname);
    String sql = "  select value from fdgyl_parameters where dr = 0 and code ='"+code+"';" ;
    ArrayList list = null;
    try {
        list = (ArrayList) dao.executeQuery(sql, new ArrayListProcessor());
    } catch (DAOException e) {
        e.printStackTrace();
    }
    if (list == null || list.size() <= 0) {
        return null;
    }
    Object[] objs = list.toArray(); // 如果存在数据
    Object[] values = (Object[]) objs[0];
    String value = values[0] == null ? null : values[0].toString();
    return value;
}

19、根据主键查询hvo bvo

@Override
    public BzqcHVO queryBzqcHVOByPk(String pk_bzqc) throws BusinessException {
        BaseDAO dao = new BaseDAO(design);
        BzqcHVO vo = null;
        vo = (BzqcHVO) dao.retrieveByPK(BzqcHVO.class,pk_bzqc);    
        return vo;
    }
 
    @Override
    public BzqcBVO[] queryBzqcBVOSByPk(String pk_bzqc) throws BusinessException {
        BaseDAO dao = new BaseDAO(design);
        String wheresql = " dr = 0 and pk_bzqc = '"+pk_bzqc+"' ";
        List<BzqcBVO> bodyVos = (List<BzqcBVO>) dao.retrieveByClause(BzqcBVO.class, wheresql);
        BzqcBVO[] bvos = (BzqcBVO[]) bodyVos.toArray(new BzqcBVO[0]);
        return bvos;
    }

20、业务锁

    //业务锁:把业务锁放在事务之外,可行原因主要有业务锁不是基于数据库和业务锁是基于Select的处理,无需事务。
    public void updateAreaclVO(AreaclVO vo) {
        boolean islock = PKLock.getInstance().acquireLock(vo.getPrimaryKey(),null, null);
if (!islock)
            try {
                throw new nc.vo.pub.BusinessException(nc.vo.bd.BDMsg.MSG_LOCKED());
            } catch (BusinessException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        try {
            String[] updateFields = null;
            String[] fields = vo.getAttributeNames();
            Vector v = new Vector();
            v.add("vdef1");
            if (v.size() > 0) {
                updateFields = new String[v.size()];
                updateFields = (String[]) v.toArray(updateFields);
            }
            try {
                new BaseDAO().updateVO(vo, updateFields);
            } catch (DAOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // 解锁
        finally {
            PKLock.getInstance().releaseLock(vo.getPrimaryKey(), null, null);
        }
    }

21 读取文件

  public class ExceptionTest {
        public static void main(String[] args) {
            String file = "D:\\exceptionTest.txt";
            FileReader reader;
            try {
                reader = new FileReader(file);
                Scanner in = new Scanner(reader);  
                String string = in.next();  
                System.out.println(string + "不知道我有幸能够执行到不.....");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.out.println("对不起,你执行不到...");
            }  
            finally{
                System.out.println("finally 在执行...");
            }
        }
    }

原文链接:https://blog.csdn.net/weixin_48692740/article/details/130481191

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值