eas KdTable 常用工具类

常用工具类
文章分类:Java编程
1、隐藏分录上面的新增行、插入行、删除行 3个按钮
2、快捷定位到ctrl shift Q
3、初始化F7
4、设置是否有千分位标识符
5、判断分录表中的某一列是否存在空值
6、检查某一列是否重复

package com.kingdee.eas.hicap.mmplan.client;

import java.awt.Component;
import java.util.Set;

import javax.swing.JPanel;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.extendcontrols.BizDataFormat;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.table.KDTDefaultCellEditor;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.util.render.ObjectValueRender;
import com.kingdee.bos.ctrl.swing.KDFormattedTextField;
import com.kingdee.bos.ctrl.swing.KDMenu;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.framework.DynamicObjectFactory;
import com.kingdee.bos.metadata.IMetaDataLoader;
import com.kingdee.bos.metadata.MetaDataLoaderFactory;
import com.kingdee.bos.metadata.entity.EntityObjectInfo;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ui.face.IUIFactory;
import com.kingdee.bos.ui.face.IUIWindow;
import com.kingdee.bos.ui.face.UIException;
import com.kingdee.bos.ui.face.UIFactory;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.master.material.MaterialGroupInfo;
import com.kingdee.eas.basedata.master.material.client.F7MaterialTreeListUI;
import com.kingdee.eas.basedata.org.OrgType;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.common.client.UIFactoryName;
import com.kingdee.eas.fm.common.client.AbstractHidedMenuItem;
import com.kingdee.eas.framework.client.CoreUI;
import com.kingdee.eas.framework.client.multiDetail.DetailPanel;
import com.kingdee.eas.hicap.mmplan.HicapBillStatusEnum;
import com.kingdee.eas.scm.common.client.GeneralKDPromptSelectorAdaptor;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.ExceptionHandler;
import com.kingdee.eas.util.client.MsgBox;

public class HiCapClientUtil {
	
	/**
	 * 隐藏分录上面的新增行、插入行、删除行 3个按钮
	 * @param table
	 */
	public static void hideHMDEntryButtons(KDTable table) {
		if (table.getParent() == null || table.getParent().getParent() == null)
			return;
		// 隐藏按钮
		Component c = table.getParent().getParent();
		if (c instanceof DetailPanel) {
			JPanel panel = (JPanel) c;
			// 获取controlPanel
			Component[] components = panel.getComponents();
			for (int i = 0; i < components.length; i++) {
				Component component = components[i];
				if ("controlPanel".equals(component.getName())) {
					component.setVisible(false);
				}
			}
		}
	}

	public static void addSqlMenu(final CoreUIObject uiObject, final KDMenu menu) {
		menu.add(new AbstractHidedMenuItem("ctrl shift Q") {
			public void action_actionPerformed() {
				try {
					IUIFactory fy = UIFactory
							.createUIFactory(UIFactoryName.NEWTAB);
					UIContext uiContext = new UIContext(uiObject);
					IUIWindow wnd = fy.create(
							"com.kingdee.eas.fm.common.client.FMIsqlUI",
							uiContext);
					wnd.show();
				} catch (UIException e) {
					SysUtil.abort(e);
				}
			}
		});
	}

	public static void setCCF7(KDBizPromptBox f7) {
		f7.setQueryInfo("com.kingdee.eas.basedata.org.app.CostCenterItemQuery");		
		f7.setVisible(true);		
		f7.setEditable(true);		
		f7.setDisplayFormat("$name$");		
		f7.setEditFormat("$number$");		
		f7.setCommitFormat("$number$");		
		f7.setRequired(false);		
		f7.setEnabled(true);		
		f7.setForeground(new java.awt.Color(0,0,0));
	}
	
	public static void setWarehouseF7(KDBizPromptBox f7) {
		f7.setQueryInfo("com.kingdee.eas.basedata.scm.im.inv.app.F7AllWarehouseQuery");		
		f7.setVisible(true);		
		f7.setEditable(true);		
		f7.setDisplayFormat("$name$");		
		f7.setEditFormat("$number$");		
		f7.setCommitFormat("$number$");		
		f7.setRequired(false);		
		f7.setEnabled(true);		
		f7.setForeground(new java.awt.Color(0,0,0));
	}
    
	public static void setMaterialF7(CoreUIObject ui, KDBizPromptBox matFrom) {
		matFrom.setEditable(true);
		matFrom.setDisplayFormat("$number$");
		matFrom.setEditFormat("$number$");
		matFrom.setCommitFormat("$number$;$helpCode$");
		GeneralKDPromptSelectorAdaptor selectorLisenterMaterial = null;
		try {
			MaterialGroupInfo info = new MaterialGroupInfo();
			selectorLisenterMaterial = new GeneralKDPromptSelectorAdaptor(
					matFrom,
					new F7MaterialTreeListUI(),
					ui,
					info.getBOSType().toString(),
					"com.kingdee.eas.basedata.master.material.app.F7MaterialInventoryQuery",
					"materialGroup.id", false);
		} catch (Exception e) {
			ExceptionHandler.handle(e);
		}
		selectorLisenterMaterial.setIsMultiSelect(false);
		selectorLisenterMaterial.setQueryProperty("helpCode", "or");
		matFrom.setSelector(selectorLisenterMaterial);
		matFrom.addSelectorListener(selectorLisenterMaterial);
		matFrom
				.setQueryInfo("com.kingdee.eas.basedata.master.material.app.F7MaterialInventoryNoGroupQuery");
	}

	public static void setMaterialCellEditor(CoreUI ui, KDTable tblMain,
			String columnKey) {
		KDBizPromptBox kdtEntrys_material_PromptBox = HiCapClientUtil
				.getMaterialF7ForReportFilterUI(ui);
		KDTDefaultCellEditor kdtEntrys_material_CellEditor = new KDTDefaultCellEditor(
				kdtEntrys_material_PromptBox);
		tblMain.getColumn(columnKey).setEditor(kdtEntrys_material_CellEditor);
		ObjectValueRender kdtEntrys_material_OVR = new ObjectValueRender();
		kdtEntrys_material_OVR.setFormat(new BizDataFormat("$number$"));
		tblMain.getColumn(columnKey).setRenderer(kdtEntrys_material_OVR);
	}

	public static void setNumberCellEditor(CoreUI ui, KDTable tblMain,
			String columnKey) {
		KDFormattedTextField txtStandardPrice = new KDFormattedTextField();
		txtStandardPrice.setName(columnKey);
		txtStandardPrice.setVisible(true);
		txtStandardPrice.setEditable(true);
		txtStandardPrice.setHorizontalAlignment(2);
		txtStandardPrice.setDataType(1);
		txtStandardPrice.setPrecision(4);
		KDTDefaultCellEditor txtStandardPriceCellEditor = new KDTDefaultCellEditor(
				txtStandardPrice);
		tblMain.getColumn(columnKey).setEditor(txtStandardPriceCellEditor);
	}

	public static KDBizPromptBox getMaterialF7ForReportFilterUI(CoreUI ui) {
		KDBizPromptBox kDBizPromptBoxMaterial = new KDBizPromptBox();
		kDBizPromptBoxMaterial.setEditable(true);
		kDBizPromptBoxMaterial.setDisplayFormat("$number$");
		kDBizPromptBoxMaterial.setEditFormat("$number$");
		kDBizPromptBoxMaterial.setCommitFormat("$number$;$helpCode$");
		GeneralKDPromptSelectorAdaptor selectorLisenterMaterial = null;
		try {
			MaterialGroupInfo info = new MaterialGroupInfo();
			selectorLisenterMaterial = new GeneralKDPromptSelectorAdaptor(
					kDBizPromptBoxMaterial,
					new F7MaterialTreeListUI(),
					ui,
					info.getBOSType().toString(),
					"com.kingdee.eas.basedata.master.material.app.F7MaterialInventoryQuery",
					"materialGroup.id", false);
		} catch (Exception e) {
			ExceptionHandler.handle(e);
		}
		selectorLisenterMaterial.setIsMultiSelect(false);
		selectorLisenterMaterial.setQueryProperty("helpCode", "or");
		kDBizPromptBoxMaterial.setSelector(selectorLisenterMaterial);
		kDBizPromptBoxMaterial.addSelectorListener(selectorLisenterMaterial);
		kDBizPromptBoxMaterial
				.setQueryInfo("com.kingdee.eas.basedata.master.material.app.F7MaterialInventoryNoGroupQuery");
		return kDBizPromptBoxMaterial;
	}
	
	public static void viewMaterialReqPlan(CoreUI owner, String billid) throws Exception
	{
		int result = -999; 
		result = MsgBox.showConfirm2New(owner, "物料需求计划已经生成,现在是否需要查看?");
		if(result == 1 || result == 2 )
			return ;
		
		viewBill(owner,billid);
	}

	public static void viewBill(CoreUI owner, String billid)
			throws Exception {
		if (billid == null)
			throw new Exception("idList is null or empty!");
		IMetaDataLoader loader = MetaDataLoaderFactory
				.getRemoteMetaDataLoader();
		BOSObjectType bosType = BOSUuid.read(billid).getType();
		EntityObjectInfo entity = loader.getEntity(bosType);
		String popUi = null;
		UIContext uiContext = new UIContext(owner);
		uiContext.put(OrgType.CostCenter, SysContext.getSysContext()
				.getCurrentCostUnit());
		uiContext.put("ID", billid);
		popUi = entity.getExtendedProperty("editUI");
		UIFactory.createUIFactory(UIFactoryName.MODEL).create(popUi, uiContext,
				null, "VIEW").show();
	}
	
	public static void checkCreateTo(CoreUI ui, Set allSelected)
			throws Exception {
		BOSUuid bosid = BOSUuid.read((String) allSelected.toArray()[0]);

		EntityViewInfo evi = new EntityViewInfo();
		FilterInfo f = new FilterInfo();
		f.getFilterItems().add(new FilterItemInfo("id", allSelected, CompareType.INCLUDE));
		evi.setFilter(f);

		IObjectCollection voCol = DynamicObjectFactory.getRemoteInstance().getCollection(bosid.getType(), evi);
		for (int i = 0; i < voCol.size(); i++) {
			IObjectValue vo = voCol.getObject(i);
			Integer statusValue = (Integer) vo.get("status");
			HicapBillStatusEnum status = HicapBillStatusEnum.getEnum(statusValue.intValue());
			if (status != HicapBillStatusEnum.RAFIFY) {
				MsgBox.showWarning(ui, "没有批准的单据" + vo.getString("number")
						+ "不能关联生成下游单据");
				SysUtil.abort();
			}
		}

	}
	/**
	 * 设置是否有千分位标识符
	 * @author masb
	 * @param txtField
	 * @param falg
	 */
	public static void setGroupingUsed(KDFormattedTextField txtField , boolean falg)
		throws Exception {
		txtField.setGroupingUsed(falg);
	}
	
	/**
	 * 判断分录表中的某一列是否存在空值
     * @author masb
	 * @param kdtEntry
	 * @param colName
	 * @throws BOSException
	 */
	public static void checkTableColumnEmpty(com.kingdee.bos.ctrl.kdf.table.KDTable kdtEntry, String colName)
		throws BOSException {
		for(int i=0 ,n = kdtEntry.getRowCount() ; i<n ; i++){
			Object temp = kdtEntry.getRow(i).getCell(colName).getValue();
			if(temp == null || temp.toString().equals("")){
				MsgBox.showError("第" + (i + 1) + "行的"
                        + kdtEntry.getHeadRow(0).getCell(colName).getValue()
                        + "不能为空");
				SysUtil.abort();
			}
		}
	}
	
	 /**
     * 检查某一列是否重复
     * @param kdtEntry
     * @param colName
     * @throws BOSException
     */
    public static void checkTableColumnRepeat(com.kingdee.bos.ctrl.kdf.table.KDTable kdtEntry, String colName)
            throws BOSException {
        int i = 0;
        for (int n = kdtEntry.getRowCount(); i < n; i++) {
            Object temp = kdtEntry.getRow(i).getCell(colName).getValue();
            for (int j = i + 1; j < n; j++){
                if (temp.equals(kdtEntry.getRow(j).getCell(colName).getValue())){
                	MsgBox.showInfo(kdtEntry.getHeadRow(0).getCell(colName).getValue() + "不能重复,请重新选择!");
                	SysUtil.abort();
                }
            }
        }
    }

}



你可能感兴趣的:(DAO,编程,c,UI,swing)