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

📄 ininventorybilllistui.java

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

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.Set;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.cownew.PIS.base.numberMgr.common.INumberRuleDAO;
import com.cownew.PIS.framework.client.ClientContextMgr;
import com.cownew.PIS.framework.client.RemoteServiceLocator;
import com.cownew.PIS.framework.common.IValueObject;
import com.cownew.PIS.framework.common.db.Selectors;
import com.cownew.PIS.inv.common.IInInventoryBillDAO;
import com.cownew.PIS.inv.common.InInvBillStateEnum;
import com.cownew.PIS.inv.common.InInventoryBillDetailInfo;
import com.cownew.PIS.inv.common.InInventoryBillInfo;
import com.cownew.PIS.inv.common.InvException;
import com.cownew.PIS.ui.base.IUIContainer;
import com.cownew.PIS.ui.base.UIFactory;
import com.cownew.PIS.ui.commonUI.EditUI;
import com.cownew.PIS.ui.commonUI.EditUIModeEnum;
import com.cownew.PIS.ui.commonUI.ListUI;
import com.cownew.PIS.ui.commonUI.filterUI.FilterSortItem;
import com.cownew.PIS.ui.commonUI.filterUI.FilterUI;
import com.cownew.PIS.ui.utils.PISAbstractAction;
import com.cownew.PIS.ui.utils.UIUtils;
import com.cownew.ctk.ui.swing.MsgBox;

public class InInventoryBillListUI extends ListUI
{

	private FilterUI filterUI;
	protected ActionAccountBill actionAccountBill;
	protected ActionGenRedBill actionGenRedBill;
	
	public InInventoryBillListUI() throws Exception
	{
		super();
	}

	protected void initAction()
	{
		super.initAction();
		actionAccountBill = new ActionAccountBill("登帐");
		actionGenRedBill = new ActionGenRedBill("生成红单");
	}
	
	protected void initToolBar(JToolBar tBar)
	{
		super.initToolBar(tBar);
		JButton btnAccountBill = new JButton();
		btnAccountBill.setAction(actionAccountBill);
		tBar.add(btnAccountBill);
		
		JButton btnGenRedBill = new JButton();
		btnGenRedBill.setAction(actionGenRedBill);
		tBar.add(btnGenRedBill);
	}
	
	public IValueObject generateNewVO() throws Exception
	{
		InInventoryBillInfo info = new InInventoryBillInfo();
		INumberRuleDAO numDAO = (INumberRuleDAO) RemoteServiceLocator
				.getRemoteService(INumberRuleDAO.class);
		info.setNumber(numDAO.generateSN("入库单编码规则"));
		info.setCreateDate(ClientContextMgr.getServerSQLNow());
		info.setOperator(ClientContextMgr.getCurrencyUser().getPerson());
		info.setIsRedBill(false);
		info.setBillState(InInvBillStateEnum.SAVED.getName());
		return info;
	}
	
	protected void actionEdit_actionPerformed(ActionEvent e) throws Exception
	{
		IInInventoryBillDAO intf = (IInInventoryBillDAO) getRemoteService();
		// 虽然在服务器端update的时候还要做判断,不过在用户点击编辑的时候就判断一下还是比较友好的,
		// 省的用户编辑了半天才发现不能保存
		if (!intf.isSavedState(getSelectedId()))
		{
			throw new InvException(InvException.NOTSAVEDCANNOTEDIT);
		}
		super.actionEdit_actionPerformed(e);
	}
	
	
	protected void actionAccountBill_Performed(ActionEvent e) throws Exception
	{
		UIUtils.checkSelected(getTableMain());
		IInInventoryBillDAO dao = (IInInventoryBillDAO) getRemoteService();
		dao.accountBill(getSelectedId());
		refreshData();
		MsgBox.showInfo(this, "登帐成功!");
	}

	protected void actionGenRedBill_Performed(ActionEvent e) throws Exception
	{
		UIUtils.checkSelected(getTableMain());
		IInInventoryBillDAO dao = (IInInventoryBillDAO) getRemoteService();
		String pk = getSelectedId();
		
		//不能对红单再次红冲
		if(dao.isRedBill(pk))
		{
			throw new InvException(InvException.CANNOTREDAGAIN);
		}
		
		Selectors selectors = new Selectors();
		selectors.add("details");
		selectors.add("details.material");
		selectors.add("details.measureUnit");

		InInventoryBillInfo billInfo = (InInventoryBillInfo) dao.loadByPK(pk,selectors);
			
		//单据复制生成一张新的出库单,清空新单据的编号,将新单据的制单日期修改为当前日期,清空登帐日期,操作员设定为当前用户
		//是否红单设置为“是”,单据状态为“保存”,并设置备注为“**的红单”(**代表被红冲单据的编号)
		billInfo.setId(null);
		INumberRuleDAO numDAO = (INumberRuleDAO) RemoteServiceLocator
		.getRemoteService(INumberRuleDAO.class);
		billInfo.setDescription(billInfo.getNumber()+"的红单");
		billInfo.setNumber(numDAO.generateSN("入库单编码规则"));
		billInfo.setAccountDate(null);
		billInfo.setOperator(ClientContextMgr.getCurrencyUser().getPerson());
		billInfo.setIsRedBill(true);
		billInfo.setBillState(InInvBillStateEnum.SAVED.getName());
		
		
		//遍历新单据的物品分录,将所有记录的“数量”、“基本数量”、“金额”取相反数
		Set detailSet = billInfo.getDetails();
		Iterator it = detailSet.iterator();
		while (it.hasNext())
		{
			InInventoryBillDetailInfo dInfo = (InInventoryBillDetailInfo) it.next();
			dInfo.setQty(dInfo.getQty().negate());
			dInfo.setBaseQty(dInfo.getBaseQty().negate());
			dInfo.setAmount(dInfo.getAmount().negate());
		}
		
		//弹出单据新增界面显示这张复制生成的单据
		Window window = SwingUtilities.getWindowAncestor(this);
		IUIContainer editUICont = UIFactory.getUIDialogContainer(getEditUIClass()
				.getName(), window);
		EditUI editUI = (EditUI) editUICont.getUIPanel();
		editUI.setMode(EditUIModeEnum.UNSAVED);
		editUI.setModelVO(billInfo);
		editUI.loadToUI();
		editUICont.show();
		refreshData();
	}
	
	protected FilterUI getFilterUI()
	{
		if(filterUI!=null)
		{
			return filterUI;
		}
		
		FilterSortItem[] sortProps = new FilterSortItem[] {
				new FilterSortItem("number", "编号"),
				new FilterSortItem("createDate", "制单日期"),
				new FilterSortItem("inDate", "入库日期"),
				new FilterSortItem("accountDate", "登帐日期"),
				new FilterSortItem("operator.name", "操作员"),
				new FilterSortItem("isRedBill", "是否红单"),
				new FilterSortItem("billState", "单据状态")};
		filterUI = new FilterUI(new InInvBillSysDefFilterUI(), sortProps);
		return filterUI;
	}

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

	public Class getServiceIntfClass()
	{
		return IInInventoryBillDAO.class;
	}
	
	protected class ActionAccountBill extends PISAbstractAction
	{

		public ActionAccountBill(String name, Icon icon)
		{
			super(name, icon);
		}

		public ActionAccountBill(String name)
		{
			super(name);
		}

		public void onActionPerformed(ActionEvent e) throws Exception
		{
			actionAccountBill_Performed(e);
		}

	}
	
	protected class ActionGenRedBill extends PISAbstractAction
	{

		public ActionGenRedBill(String name, Icon icon)
		{
			super(name, icon);
		}

		public ActionGenRedBill(String name)
		{
			super(name);
		}

		public void onActionPerformed(ActionEvent e) throws Exception
		{
			actionGenRedBill_Performed(e);
		}

	}

	

}

⌨️ 快捷键说明

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