BOS中控件非空 非0校验

 protected void verifyInput(ActionEvent arg0) throws Exception {
		    	super.verifyInput(arg0);
		    	//非空校验
		    	HashMap<String, Object> verifyNullMap=new HashMap();
		    	verifyNullMap.put("库存组织", prmtStorageOrgUnit);
		    	verifyNullMap.put("工程类别", prmtProjectType);
		    	verifyNullMap.put("设计量", txtDesignQty);
		    	verifyNullMap.put("计量类型", comboMeasureType);	
		    	String [] strTmp=verifyNullMap.keySet().toArray(new String[verifyNullMap.size()]);
		    	for(int i=verifyNullMap.size()-1;i>=0;i--)
		    		CanNotNull(verifyNullMap.get(strTmp[i]),strTmp[i]);
		    	//非0校验 可为空
		    	HashMap<String, Object> verifyZeroMap=new HashMap();
		    	verifyZeroMap.put("设计量", txtDesignQty);
		    	String [] strZeroTmp=verifyZeroMap.keySet().toArray(new String[verifyZeroMap.size()]);
		    	for(int i=verifyZeroMap.size()-1;i>=0;i--)
		    		CanNotZero(verifyZeroMap.get(strZeroTmp[i]),strZeroTmp[i]);
		    	
		    }
		    //非空校验函数
		    protected void CanNotNull(Object obj,String message)
		    {	
		    	if((obj instanceof KDBizPromptBox && ((KDBizPromptBox)obj).getValue()==null)||
		    	   (obj instanceof KDComboBox && ((KDComboBox)obj).getSelectedItem()==null )||
		    	   (obj instanceof KDFormattedTextField &&((KDFormattedTextField)obj).getValue()==null))
		    	{
		    		MsgBox.showInfo(message+"不能为空!");
		    		((JComponent)obj).requestFocus();
		    		abort();
		    	}
		    }
		    //非0校验函数 可为空
		    protected void CanNotZero(Object obj,String message)
		    {
		    	if(obj instanceof KDFormattedTextField && ((KDFormattedTextField)obj).getValue()!=null &&
		    		(((KDFormattedTextField)obj).getBigDecimalValue().compareTo(BigDecimal.ZERO)==0))
		    	{
		    		MsgBox.showInfo(message+"值不能为  '0' !");
		    		((JComponent)obj).requestFocus();
		    		abort();
		    	}
		    }


posted @ 2012-05-01 21:31  范永强  阅读(202)  评论(0编辑  收藏  举报