BOS开发之自定义查询

在客户端手动查询数据的实例代码  回复  引用  编辑 

用客户排队系统为例,在开票单界面,可以自定义查询过磅单信息

有两种实现方式,一种是事先建立查询对象,只需要在按钮事件里设置查询条件即可;另外一种是,建立后台方法,手动写SQL返回数据集。

一、使用查询对象的方式

1、查询界面:



2、创建查询对象



3、将查询对象绑定到表格界面:

切换到设计视图,在表格上点右键,即可以看到“绑定”数据源的功能





选择我们已经建立好的查询对象,并根据需要调整字段,表格就已经可以自动出数据了

4、按钮事件:

4.1、建立按钮事件(略)

4.2、重写按钮事件:

    @Override
    protected void btnSearch_actionPerformed(java.awt.event.ActionEvent e) throws Exception
    { 
     //refreshCustSearch();
     String searchKey = txtSearch.getText().trim(); 
     if(searchKey.equals("客户名称/车牌号"))
      return;
     FilterInfo filter = new FilterInfo();
     FilterItemInfo name = new FilterItemInfo("carNum","%" + searchKey+"%",CompareType.LIKE);
     FilterItemInfo cph = new FilterItemInfo("customer.name","%"+searchKey+"%",CompareType.LIKE);
     filter.getFilterItems().add(name);
     filter.getFilterItems().add(cph);
     filter.setMaskString("#0 OR #1");
     queryKaiPiaoListQuery.setFilter(filter);
        tblCust.removeRows();
    
    }

第一种方式的功能即已实现


Re: 在客户端手动查询数据的实例代码  回复  引用  编辑 

方法二:不用查询对象,使用定义功能函数的方式。

1、打开实体,建立方法





2、在Bean里实现该方法:

@Override
    protected IRowSet _getBangList(Context ctx, String searchKey) throws BOSException
    {    
     Boolean haveSearch = false;
     List<String> params = new java.util.ArrayList<String>();
     StringBuffer sql = new StringBuffer();
     sql.append("SELECT ")
     .append("\"GUOBANG\".CFCarNum AS \"CARNUM\", ")
  .append("\"GUOBANG\".CFTare AS \"TARE\", ")
  .append("\"GUOBANG\".CFState AS \"STATE\", ")
  .append("\"GUOBANG\".CFBillOrder AS \"BILLORDER\", ")
  .append("\"GUOBANG\".FNumber AS \"NUMBER\", ")
  .append("\"GUOBANG\".FBizDate AS \"BIZDATE\", ")
  .append("\"GUOBANG\".FCreateTime AS \"CREATETIME\", ")
  .append("\"CUSTOMER\".FName_l2 AS \"CUSTOMER.NAME\", ")
  .append("\"CUSTOMER\".FNumber AS \"CUSTOMER.NUMBER\", ")
  .append("\"CUSTOMER\".FMnemonicCode AS \"CUSTOMER.MNEMONICCODE\"")
  .append(" FROM CT_HT_GuoBang AS \"GUOBANG\"")
  .append(" LEFT OUTER JOIN T_BD_Customer AS \"CUSTOMER\"")
  .append(" ON \"GUOBANG\".CFCustomerID = \"CUSTOMER\".FID")
  .append(" LEFT OUTER JOIN T_PM_User AS \"CREATOR\"")
  .append(" ON \"GUOBANG\".FCreatorID = \"CREATOR\".FID")
  .append(" WHERE \"GUOBANG\".CFState = '1'");
     if(searchKey!=null && !"".equals(searchKey.trim()))
     {
      haveSearch = true;
      params.add(searchKey.trim());
      params.add(searchKey.trim());
      sql.append(" AND (CHARINDEX(?,\"GUOBANG\".CFCarNum) > 0 OR CHARINDEX(?,\"CUSTOMER\".FName_l2) > 0)");
     }
     sql.append(" ORDER BY \"GUOBANG\".FCreateTime");
     if(haveSearch)
      return com.kingdee.eas.util.app.DbUtil.executeQueryNoTx(ctx, sql.toString(),params.toArray());
     else
      return com.kingdee.eas.util.app.DbUtil.executeQuery(ctx,sql.toString());
    }

3、客户端调用

@Override
    protected void btnSearch_actionPerformed(java.awt.event.ActionEvent e) throws Exception
    { 
     tblCust.removeRows();
     String searchKey = txtSearch.getText().trim(); 
     if(searchKey.equals("客户名称/车牌号"))
      searchKey="";        
     try {      
      IKaiPiao kp = KaiPiaoFactory.getRemoteInstance();
      IRowSet rowset = kp.getBangList(searchKey);
      if(rowset!=null)
      {
       while(rowset.next())
       {
        IRow row = tblCust.addRow();       
        ICell cell = row.getCell(0);
        cell.setValue(rowset.getString("NUMBER"));
        cell = row.getCell(1);       
        cell.setValue(rowset.getString("BILLORDER"));
        cell = row.getCell(2);       
        cell.setValue(rowset.getString("CUSTOMER.NAME"));
        cell = row.getCell(3);
        cell.setValue(rowset.getString("CARNUM"));       
       }
      }     
                   
        } catch (Exception ee) {
            handUIException(ee);
            //MsgBox.show(ee.getMessage());
        }    
    }

全部功能完成


你可能感兴趣的:(BOS企业应用开发)