nc 刷新时调动风车界面

1.总体思路 nc 刷新的方法就是继承刷新默认的class 类,然后在action类中 获取页面的id 通过id来查询数据,将查到的数据用实体的数据接收,然后塞到modle中显示即可。

需要注意的有两点 一时 注意sql的优化,比如多个id查询 最好不要用for 循环遍历去一个一个查 最好是用in来查询,还有一个需要注意 用in查询 字段最好不要超过3000.

在查询过程中,由于数据量比较大,需要调用风车界面 ,在数据没查完 需要调用它 ,调完了 就结束。

具体代码如下:

package nc.ui.am.actions.batch;


import java.awt.Container;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;


import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.am.file.ace.view.ShowBatchBillTable;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.progress.DefaultProgressMonitor;
import nc.ui.pub.beans.progress.IProgressMonitor;
import nc.ui.pubapp.uif2app.model.BatchBillTableModel;
import nc.ui.uif2.ShowStatusBarMsgUtil;
import nc.ui.uif2.actions.batch.BatchRefreshAction;
import nc.ui.uif2.components.progress.TPAProgressUtil;
import nc.vo.am.file.EquipmentPrice;
import nc.vo.pub.BusinessException;




public class MyBatchRefresh extends BatchRefreshAction{


private static final long serialVersionUID = 7719479915326525195L;
private ShowBatchBillTable editor;
private BatchBillTableModel model = null;
private IUAPQueryBS query;
private TPAProgressUtil tpaProgressUtil;
private Container parent;
public MyBatchRefresh() {
super();
setBtnName("刷新");
setCode("refreshAction");
}


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


new Thread(new Runnable() {
@Override
public void run() {
//方案计算进度条
DefaultProgressMonitor montior = getTpaProgressUtil().getTPAProgressMonitor();
montior.beginTask("正在刷新,请稍等..........", IProgressMonitor.UNKNOWN_TOTAL_TASK);
montior.setProcessInfo("正在刷新,请稍等..........");
    try {
refresh();
} catch (BusinessException e) {

e.printStackTrace();
}
montior.done();
MessageDialog.showHintDlg(parent, "提示", "刷新成功!!");
}}).start();


}


/**
* pk_equip是这种形式'','','',...,''
* @param pk_equip
* @return
* @throws BusinessException 
*/
public void refresh() throws BusinessException{
int rows = this.getEditor().getBillCardPanel().getBillModel().getRowCount();
if(rows<=0){//表示没有数据,则不用更新界面
return;
}
//准备容器
List result =new ArrayList();

//获取所有设备的主键并拼接成这种形式'','','',...,''
StringBuffer box = new StringBuffer();//存放设备主键

for(int i=0;iString pk_equip=(String) this.getEditor().getBillCardPanel().getBodyValueAt(i, "pk_equip");
box.append("'"+pk_equip+"',");
//判断当box的长度是3000的倍数,执行一次查询
if(box.length()%2700==0){
//查询数据
String sql=this.getSql(box.substring(0, box.lastIndexOf(",")));
@SuppressWarnings("unchecked")
List  equipmentPrice=  (List) getQuery().executeQuery(sql, new BeanListProcessor(EquipmentPrice.class));    
  //清空字符串
box.delete(0, 2700);
//添加list数组
result.addAll(equipmentPrice);
}

}
 //循环完查询多余的主键
String sql=this.getSql(box.substring(0, box.lastIndexOf(",")));
List  equipmentPrice=  (List) getQuery().executeQuery(sql, new BeanListProcessor(EquipmentPrice.class));    
result.addAll(equipmentPrice);
//更新界面
if (result != null && result.size()>0) {
this.getModel().initModel(result.toArray(new EquipmentPrice[0]));
}

//显示状态值
ShowStatusBarMsgUtil.showStatusBarMsg("成功刷新"+rows+"条数据", model.getContext());

}
private String getSql(String pk_equip) {
StringBuffer sql = new StringBuffer();
sql.append(" select ");
sql.append(" pk_equip pk_list , ");
sql.append(" pk_equip pk_equip, ");
sql.append(" def1 price, ");
sql.append(" def2 category, ");
sql.append(" pk_group pk_group, ");
sql.append(" pk_org pk_org, ");
sql.append(" borrow_flag state, ");
sql.append(" creator creator, ");
sql.append(" creationtime creationtime, ");
sql.append(" modifier modifier, ");
sql.append(" modifiedtime modifiedtime ");
sql.append(" from pam_equip ");
sql.append(" where  pam_equip.dr=0 ");
sql.append(" and  equip_code in ("+pk_equip+") ");
return sql.toString();
}




public IUAPQueryBS getQuery(){
if(query==null){
query=NCLocator.getInstance().lookup(IUAPQueryBS.class);
}
return query;
}


public ShowBatchBillTable getEditor() {
return editor;
}


public void setEditor(ShowBatchBillTable editor) {
this.editor = editor;
}


public BatchBillTableModel getModel() {
return model;
}


public void setModel(BatchBillTableModel model) {
this.model = model;
model.addAppEventListener(this);
}
private TPAProgressUtil getTpaProgressUtil() {
if (tpaProgressUtil == null) {
tpaProgressUtil = new TPAProgressUtil();
tpaProgressUtil.setContext(getModel().getContext());  //此句不可以少,否则报空指针异常
}
return tpaProgressUtil;
}


}

你可能感兴趣的:(nc 刷新时调动风车界面)