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

📄 countinventorybilleditui.java

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

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.math.BigDecimal;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

import com.cownew.PIS.basedata.common.IMaterialDAO;
import com.cownew.PIS.basedata.common.IMeasureUnitDAO;
import com.cownew.PIS.basedata.common.IPersonDAO;
import com.cownew.PIS.basedata.common.MaterialInfo;
import com.cownew.PIS.basedata.common.MeasureUnitGroupInfo;
import com.cownew.PIS.basedata.common.MeasureUnitInfo;
import com.cownew.PIS.common.validator.IValidator;
import com.cownew.PIS.framework.client.ClientMetaDataLoaderFactory;
import com.cownew.PIS.framework.common.IValueObject;
import com.cownew.PIS.framework.common.db.Selectors;
import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.inv.common.CountInvBillStateEnum;
import com.cownew.PIS.inv.common.CountInvTypeEnum;
import com.cownew.PIS.inv.common.CountInventoryBillDetailInfo;
import com.cownew.PIS.inv.common.CountInventoryBillValidator;
import com.cownew.PIS.inv.common.ICountInventoryBillDAO;
import com.cownew.PIS.ui.commonUI.SimpleTableEditUI;
import com.cownew.PIS.ui.ctrl.prompt.PopupDatePicker;
import com.cownew.PIS.ui.ctrl.prompt.OVPicker.PopupValueObjectPicker;
import com.cownew.PIS.ui.ctrl.query.QueryExecutor;
import com.cownew.PIS.ui.ctrl.table.NumberCellEditor;
import com.cownew.PIS.ui.ctrl.table.ReadOnlyTableCellEditor;
import com.cownew.PIS.ui.ctrl.table.ValueObjectCellEditor;
import com.cownew.PIS.ui.ctrl.table.ValueObjectCellRender;
import javax.swing.table.DefaultTableModel;
import com.cownew.ctk.ui.swing.TableUtils;

public class CountInventoryBillEditUI extends SimpleTableEditUI
{
	private static final String COL_BASEQTY = "基本数量";
	private static final String COL_QTY = "数量";
	private static final String COL_MEASUREUNIT = "计量单位";
	private static final String COL_MATERIAL = "物料";
	
	private static final int COLINDEX_MATERIAL = 1;
	private static final int COLINDEX_MEASUREUNIT = 2;
	private static final int COLINDEX_QTY = 3;
	private static final int COLINDEX_BASEQTY = 4;	

	private JLabel jLabel;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JScrollPane jScrollPane;
	private JScrollPane scrollPaneTable;
	private JTextField txtNumber;
	private PopupDatePicker pdpCreateDate;
	private PopupDatePicker pdpCountDate;
	private PopupDatePicker pdpAccountDate;
	private PopupValueObjectPicker popOperator;
	private JComboBox comboBillState;
	private JTextArea txtDesc;
	private JLabel jLabel7;
	private JComboBox comboCountType;

	public CountInventoryBillEditUI() throws Exception
	{
		super();
	}
	
	protected void verifyBeforeSubmit(IValueObject vo) throws Exception
	{
		super.verifyBeforeSubmit(vo);
		IValidator validator = new CountInventoryBillValidator(
				ClientMetaDataLoaderFactory.getLoader(), getRemoteService());
		validator.validate(vo);
	}
	
	protected void initTable(JTable table)
	{
		super.initTable(table);
		Vector tableHead = new Vector();
		tableHead.add("id");
		tableHead.add(COL_MATERIAL);
		tableHead.add(COL_MEASUREUNIT);
		tableHead.add(COL_QTY);
		tableHead.add(COL_BASEQTY);
		DefaultTableModel tableModel = new DefaultTableModel(tableHead, 0);
		table.setModel(tableModel);

		TableUtils.hideColumn(table, 0);

		ValueObjectCellEditor matCellEditor = new ValueObjectCellEditor(
				IMaterialDAO.class, "name");
		Selectors matSelectors = new Selectors();
		matSelectors.add("measureUnitGroup");
		matCellEditor.getQueryExecutor().setSelectors(matSelectors);
		table.getColumn(COL_MATERIAL).setCellEditor(matCellEditor);
		table.getColumn(COL_MATERIAL).setCellRenderer(
				new ValueObjectCellRender("name"));

		ValueObjectCellEditor muCellEditor = new ValueObjectCellEditor(
				IMeasureUnitDAO.class, "name");
		table.getColumn(COL_MEASUREUNIT).setCellEditor(muCellEditor);
		table.getColumn(COL_MEASUREUNIT).setCellRenderer(
				new ValueObjectCellRender("name"));
		
		table.getColumn(COL_QTY).setCellEditor(new NumberCellEditor());
		
		table.getColumn(COL_BASEQTY).setCellEditor(new ReadOnlyTableCellEditor());

		tableModel.addTableModelListener(new TableModelListener() {

			public void tableChanged(TableModelEvent e)
			{
				tableModel_TableChanged(e);
			}

		});
	}
	
	protected void tableModel_TableChanged(TableModelEvent e)
	{
		DefaultTableModel tableModel = (DefaultTableModel) e.getSource();
		int rowIndex = e.getFirstRow();
		//如果物品发生变化,则重置计量单位,并修改计量单位的过滤条件
		if (e.getColumn() == COLINDEX_MATERIAL)
		{
			MaterialInfo materialInfo = (MaterialInfo) tableModel.getValueAt(
					rowIndex, COLINDEX_MATERIAL);
			if (materialInfo != null)
			{
				MeasureUnitGroupInfo muGroup = materialInfo
						.getMeasureUnitGroup();
				if (muGroup != null)
				{
					ValueObjectCellEditor muCellEditor = (ValueObjectCellEditor) getTable()
							.getColumn(COL_MEASUREUNIT).getCellEditor();
					QueryExecutor muQE = muCellEditor.getQueryExecutor();
					muQE.setOQL("from " + MeasureUnitInfo.class.getName()
							+ " where head.id=:headid");
					KeyValueList kvList = new KeyValueList();
					kvList.add("headid", muGroup.getId());
					muQE.setSqlParams(kvList);
				}

			}
			
		}
		
		// 如果是计量单位或者数量列发生变化,且两者都不为空,则自动计算基本数量
		if (e.getColumn() == COLINDEX_MATERIAL
				|| e.getColumn() == COLINDEX_MEASUREUNIT
				|| e.getColumn() == COLINDEX_QTY)
		{
			MeasureUnitInfo muInfo = (MeasureUnitInfo) tableModel.getValueAt(
					rowIndex, COLINDEX_MEASUREUNIT);
			BigDecimal bdQty = (BigDecimal) tableModel.getValueAt(rowIndex,
					COLINDEX_QTY);
			if(muInfo!=null&&bdQty!=null)
			{
				BigDecimal convertRate = muInfo.getConvertRate();
				BigDecimal bdBaseQty = convertRate.multiply(bdQty);
				tableModel.setValueAt(bdBaseQty,rowIndex,COLINDEX_BASEQTY);
			}
		}
	}

	protected void initDataBind()
	{
		super.initDataBind();
		dataBinder.registerBind(getTxtNumber(), "number");
		dataBinder.registerBind(getPdpCreateDate(), "createDate");
		dataBinder.registerBind(getPdpCountDate(), "countDate");
		dataBinder.registerBind(getPdpAccountDate(), "accountDate");
		dataBinder.registerBind(getPopOperator(), "operator");
		dataBinder.registerEnumBind(getComboBillState(), CountInvBillStateEnum.class,
				"billState");
		dataBinder.registerEnumBind(getComboCountType(), CountInvTypeEnum.class,
		"countType");
		dataBinder.registerBind(getTxtDesc(), "description");
		tableDataBinder.registerBind("id", "id");
		tableDataBinder.registerBind(COL_MATERIAL, "material");
		tableDataBinder.registerBind(COL_MEASUREUNIT, "measureUnit");
		tableDataBinder.registerBind(COL_QTY, "qty");
		tableDataBinder.registerBind(COL_BASEQTY, "baseQty");
	}

	public Selectors getSelectors()
	{
		Selectors selectors = super.getSelectors();
		selectors.add("operator");
		selectors.add("details");
		selectors.add("details.material");
		selectors.add("details.measureUnit");
		return selectors;
	}
	
	/**
	 * This method initializes this
	 * 
	 */
	protected void initialize() {
		super.initialize();
        jLabel7 = new JLabel();
        jLabel7.setText("盘点类型");
        jLabel7.setLocation(new Point(10, 115));
        jLabel7.setSize(new Dimension(51, 16));
        jLabel6 = new JLabel();
        jLabel6.setText("备注");
        jLabel6.setLocation(new Point(10, 136));
        jLabel6.setSize(new Dimension(52, 16));
        jLabel5 = new JLabel();
        jLabel5.setBounds(new Rectangle(224, 79, 37, 16));
        jLabel5.setText("状态");
        jLabel4 = new JLabel();
        jLabel4.setText("操作员");
        jLabel4.setLocation(new Point(10, 80));
        jLabel4.setSize(new Dimension(52, 16));
        jLabel3 = new JLabel();
        jLabel3.setBounds(new Rectangle(224, 45, 52, 16));
        jLabel3.setText("登帐日期");
        jLabel2 = new JLabel();
        jLabel2.setText("盘点日期");
        jLabel2.setLocation(new Point(10, 45));
        jLabel2.setSize(new Dimension(52, 16));
        jLabel1 = new JLabel();
        jLabel1.setBounds(new Rectangle(224, 10, 52, 16));
        jLabel1.setText("制单日期");
        jLabel = new JLabel();
        jLabel.setText("编码");
        jLabel.setLocation(new Point(10, 10));
        jLabel.setSize(new Dimension(52, 16));
        this.setLayout(null);
        this.setSize(new Dimension(438, 305));
        this.add(jLabel, null);
        this.add(jLabel1, null);
        this.add(jLabel2, null);
        this.add(jLabel3, null);
        this.add(jLabel4, null);
        this.add(jLabel5, null);
        this.add(jLabel6, null);
        this.add(getJScrollPane(), null);
        this.add(getScrollPaneTable(), null);
        this.add(getTxtNumber(), null);
        this.add(getPdpCreateDate(), null);
        this.add(getPdpCountDate(), null);
        this.add(getPdpAccountDate(), null);
        this.add(getPopOperator(), null);
        this.add(getComboBillState(), null);
        this.add(jLabel7, null);
        this.add(getComboCountType(), null);
			
	}

	public Class getServiceIntfClass()
	{
		return ICountInventoryBillDAO.class;
	}

	protected Class getTableDataClass()
	{
		return CountInventoryBillDetailInfo.class;
	}

	protected String getTableDataProperty()
	{
		return "details";
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane()
	{
		if (jScrollPane == null)
		{
			jScrollPane = new JScrollPane();
			jScrollPane.setSize(new Dimension(403, 32));
			jScrollPane.setViewportView(getTxtDesc());
			jScrollPane.setLocation(new Point(10, 157));
		}
		return jScrollPane;
	}

	/**
	 * This method initializes scrollPaneTable	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	protected JScrollPane getScrollPaneTable()
	{
		if (scrollPaneTable == null)
		{
			scrollPaneTable = new JScrollPane();
			scrollPaneTable.setBounds(new Rectangle(10, 199, 405, 87));
			scrollPaneTable.setViewportView(getTable());
		}
		return scrollPaneTable;
	}

	/**
	 * This method initializes txtNumber	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtNumber()
	{
		if (txtNumber == null)
		{
			txtNumber = new JTextField();
			txtNumber.setLocation(new Point(76, 10));
			txtNumber.setSize(new Dimension(120, 21));
		}
		return txtNumber;
	}

	/**
	 * This method initializes pdpCreateDate	
	 * 	
	 * @return com.cownew.PIS.ui.ctrl.prompt.PopupDatePicker	
	 */
	private PopupDatePicker getPdpCreateDate()
	{
		if (pdpCreateDate == null)
		{
			pdpCreateDate = new PopupDatePicker();
			pdpCreateDate.setEnabled(false);
			pdpCreateDate.setBounds(new Rectangle(293, 10, 120, 21));
		}
		return pdpCreateDate;
	}

	/**
	 * This method initializes pdpInDate	
	 * 	
	 * @return com.cownew.PIS.ui.ctrl.prompt.PopupDatePicker	
	 */
	private PopupDatePicker getPdpCountDate()
	{
		if (pdpCountDate == null)
		{
			pdpCountDate = new PopupDatePicker();
			pdpCountDate.setBounds(new Rectangle(76, 45, 120, 21));
		}
		return pdpCountDate;
	}

	/**
	 * This method initializes pdpAccountDate	
	 * 	
	 * @return com.cownew.PIS.ui.ctrl.prompt.PopupDatePicker	
	 */
	private PopupDatePicker getPdpAccountDate()
	{
		if (pdpAccountDate == null)
		{
			pdpAccountDate = new PopupDatePicker();
			pdpAccountDate.setEnabled(false);
			pdpAccountDate.setBounds(new Rectangle(293, 45, 120, 21));
		}
		return pdpAccountDate;
	}

	/**
	 * This method initializes popOperator	
	 * 	
	 * @return com.cownew.PIS.ui.ctrl.prompt.OVPicker.PopupValueObjectPicker	
	 */
	private PopupValueObjectPicker getPopOperator()
	{
		if (popOperator == null)
		{
			popOperator = new PopupValueObjectPicker(IPersonDAO.class);
			popOperator.setEnabled(false);
			popOperator.setDisplayProperty("name");
			popOperator.setBounds(new Rectangle(76, 80, 120, 21));
		}
		return popOperator;
	}

	/**
	 * This method initializes comboBillState	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getComboBillState()
	{
		if (comboBillState == null)
		{
			comboBillState = new JComboBox();
			comboBillState.setBounds(new Rectangle(293, 76, 120, 20));
			comboBillState.setEnabled(false);
		}
		return comboBillState;
	}

	/**
	 * This method initializes txtDesc	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getTxtDesc()
	{
		if (txtDesc == null)
		{
			txtDesc = new JTextArea();
			txtDesc.setWrapStyleWord(true);
			txtDesc.setLineWrap(true);
		}
		return txtDesc;
	}

	/**
	 * This method initializes comboCountType	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getComboCountType()
	{
		if (comboCountType == null)
		{
			comboCountType = new JComboBox();
			comboCountType.setBounds(new Rectangle(76, 113, 120, 20));
		}
		return comboCountType;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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