⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 measureunitlistui.java

📁 《j2ee开发全程实录》随书源码
💻 JAVA
字号:
package com.cownew.PIS.basedata.client;

import java.awt.event.ActionEvent;
import java.util.Enumeration;
import java.util.List;

import javax.swing.DefaultListModel;

import com.cownew.PIS.basedata.common.IMeasureUnitDAO;
import com.cownew.PIS.basedata.common.IMeasureUnitGroupDAO;
import com.cownew.PIS.basedata.common.MeasureUnitGroupInfo;
import com.cownew.PIS.basedata.common.MeasureUnitInfo;
import com.cownew.PIS.framework.client.RemoteServiceLocator;
import com.cownew.PIS.framework.common.IValueObject;
import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.ui.ctrl.query.QueryExecutor;
import com.cownew.PIS.ui.utils.UIUtils;
import com.cownew.ctk.common.StringUtils;
import com.cownew.ctk.constant.BigDecimalConst;
import com.cownew.ctk.ui.swing.MsgBox;

public class MeasureUnitListUI extends AbstractMeasureUnitListUI
{

	public MeasureUnitListUI() throws Exception
	{
		super();
		loadMeasureUnitGroup();
	}

	public IValueObject generateNewVO() throws Exception
	{
		MeasureUnitGroupInfo groupInfo = getSelectedGroupInfo();
		if(groupInfo==null)
		{
			MsgBox.showError(this,"请选择计量单位所属的计量单位组!");
			return null;
		}
		
		IMeasureUnitGroupDAO muGroupDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
				.getRemoteService(IMeasureUnitGroupDAO.class);
		MeasureUnitInfo mInfo = new MeasureUnitInfo();
		mInfo.setHead(groupInfo);
		
		if(!muGroupDAO.hasBaseUnit(groupInfo.getId()))
		{
			mInfo.setIsBaseUnit(true);
			mInfo.setConvertRate(BigDecimalConst.ONE);
		}
		
		return mInfo;
	}

	public Class getEditUIClass()
	{
		return MeasureUnitEditUI.class;
	}

	public Class getServiceIntfClass()
	{
		return IMeasureUnitDAO.class;
	}
	
	protected MeasureUnitGroupInfo getSelectedGroupInfo()
	{
		return (MeasureUnitGroupInfo) getListLeft().getSelectedValue();
	}
	
	protected void loadMeasureUnitGroup() throws Exception
	{
		IMeasureUnitGroupDAO listDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
		.getRemoteService(IMeasureUnitGroupDAO.class);
		List gInfos = listDAO.loadAll();
		DefaultListModel listModel = new DefaultListModel();
		for(int i=0,n=gInfos.size();i<n;i++)
		{
			MeasureUnitGroupInfo gInfo = (MeasureUnitGroupInfo) gInfos.get(i);
			listModel.addElement(gInfo);
		}
		getListLeft().setModel(listModel);
	}

	protected void listLeft_SelectChanged() throws Exception
	{
		MeasureUnitGroupInfo gInfo = getSelectedGroupInfo();
		
		//当删除组的时候也会触发此事件,但是此时gInfo为null
		if(gInfo==null)
		{
			return;
		}
		QueryExecutor qe = getQueryExecutor();
		qe.setOQL("from "+MeasureUnitInfo.class.getName()+" where head.id=:headid");
		KeyValueList kvList = new KeyValueList();		
		kvList.add("headid",gInfo.getId());
		qe.setSqlParams(kvList);
		refreshData(qe);
	}

	protected void actionLeftAddNew_onActionPerformed(ActionEvent e)
			throws Exception
	{
		String name = MsgBox.showInput(this, "请输入计量单位组的名称");
		if (StringUtils.isEmpty(name))
		{
			return;
		}

		name = name.trim();

		DefaultListModel listModel = (DefaultListModel) getListLeft()
				.getModel();
		Enumeration en = listModel.elements();
		while (en.hasMoreElements())
		{
			MeasureUnitGroupInfo info = (MeasureUnitGroupInfo) en.nextElement();
			if (info.getName().equals(name))
			{
				MsgBox.showError(this, "计量单位组名称重复");
				return;
			}
		}

		MeasureUnitGroupInfo groupInfo = new MeasureUnitGroupInfo();
		groupInfo.setName(name);
		IMeasureUnitGroupDAO listDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
				.getRemoteService(IMeasureUnitGroupDAO.class);
		groupInfo.setId(listDAO.save(groupInfo));

		listModel.addElement(groupInfo);
	}

	protected void actionLeftEdit_onActionPerformed(ActionEvent e) throws Exception
	{
		MeasureUnitGroupInfo vo = getSelectedGroupInfo();
		if (vo == null)
		{
			MsgBox.showError(this, "请选择要编辑的计量单位组!");
			return;
		}
		
		String name = MsgBox.showInput(this, "请输入计量单位组的名称",vo.getName());
		if (StringUtils.isEmpty(name)||vo.getName().equals(name))
		{
			return;
		}
		IMeasureUnitGroupDAO listDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
				.getRemoteService(IMeasureUnitGroupDAO.class);
		listDAO.rename(vo.getId(),name);
		vo.setName(name);
	}

	protected void actionLeftDelete_onActionPerformed(ActionEvent e)
			throws Exception
	{
		IValueObject vo = getSelectedGroupInfo();
		if (vo == null)
		{
			MsgBox.showError(this, "请选择要删除的计量单位组!");
			return;
		}
		IMeasureUnitGroupDAO listDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
				.getRemoteService(IMeasureUnitGroupDAO.class);
		listDAO.delete(vo.getId());
		DefaultListModel listModel = (DefaultListModel) getListLeft().getModel();
		listModel.removeElement(vo);
		refreshData();
		MsgBox.showInfo(this, "删除成功!");
	}

	protected void actionSetBaseUnit_onActionPerformed(ActionEvent e)
			throws Exception
	{
		IValueObject vo = getSelectedGroupInfo();
		if (vo == null)
		{
			MsgBox.showError(this, "请选择要设置的计量单位组!");
			return;
		}
		UIUtils.checkSelected(getTableMain());
		IMeasureUnitGroupDAO muDAO = (IMeasureUnitGroupDAO) RemoteServiceLocator
				.getRemoteService(IMeasureUnitGroupDAO.class);
		muDAO.setBaseUnit(vo.getId(), getSelectedId());
		refreshData();
		MsgBox.showInfo(this,"基本计量单位已经变化,请修改其它计量单位的转换率!");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -