📄 ininventorybilleditui.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.JCheckBox;
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.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.IInInventoryBillDAO;
import com.cownew.PIS.inv.common.InInvBillStateEnum;
import com.cownew.PIS.inv.common.InInventoryBillDetailInfo;
import com.cownew.PIS.inv.common.InInventoryBillValidator;
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 InInventoryBillEditUI extends SimpleTableEditUI
{
private static final String COL_AMOUNT = "金额";
private static final String COL_BASEPRICE = "基本单价";
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 static final int COLINDEX_BASEPRICE = 5;
private static final int COLINDEX_AMOUNT = 6;
private JLabel jLabel;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JCheckBox cbIsRedBill;
private JLabel jLabel5;
private JLabel jLabel6;
private JScrollPane jScrollPane;
private JScrollPane scrollPaneTable;
private JTextField txtNumber;
private PopupDatePicker pdpCreateDate;
private PopupDatePicker pdpInDate;
private PopupDatePicker pdpAccountDate;
private PopupValueObjectPicker popOperator;
private JComboBox comboBillState;
private JTextArea txtDesc;
public InInventoryBillEditUI() throws Exception
{
super();
}
protected void verifyBeforeSubmit(IValueObject vo) throws Exception
{
super.verifyBeforeSubmit(vo);
InInventoryBillValidator validator = new InInventoryBillValidator(
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);
tableHead.add(COL_BASEPRICE);
tableHead.add(COL_AMOUNT);
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());
table.getColumn(COL_BASEPRICE).setCellEditor(new NumberCellEditor());
table.getColumn(COL_AMOUNT).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);
}
}
//如果基本数量或者基本单价发生变化,且两者都不为空,则自动计算金额
if(e.getColumn()==COLINDEX_BASEQTY||e.getColumn()==COLINDEX_BASEPRICE)
{
BigDecimal bdBaseQty = (BigDecimal) tableModel.getValueAt(
rowIndex, COLINDEX_BASEQTY);
BigDecimal bdBasePrice = (BigDecimal) tableModel.getValueAt(
rowIndex, COLINDEX_BASEPRICE);
if(bdBaseQty!=null&&bdBasePrice!=null)
{
BigDecimal bdAmount = bdBaseQty.multiply(bdBasePrice);
tableModel.setValueAt(bdAmount,rowIndex,COLINDEX_AMOUNT);
}
}
}
protected void initDataBind()
{
super.initDataBind();
dataBinder.registerBind(getTxtNumber(), "number");
dataBinder.registerBind(getPdpCreateDate(), "createDate");
dataBinder.registerBind(getPdpInDate(), "inDate");
dataBinder.registerBind(getPdpAccountDate(), "accountDate");
dataBinder.registerBind(getCbIsRedBill(), "isRedBill");
dataBinder.registerBind(getPopOperator(), "operator");
dataBinder.registerEnumBind(getComboBillState(), InInvBillStateEnum.class,
"billState");
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");
tableDataBinder.registerBind(COL_BASEPRICE, "basePrice");
tableDataBinder.registerBind(COL_AMOUNT, "amount");
}
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();
jLabel6 = new JLabel();
jLabel6.setText("备注");
jLabel6.setLocation(new Point(10, 115));
jLabel6.setSize(new Dimension(52, 16));
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(302, 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(222, 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(getCbIsRedBill(), 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(getPdpInDate(), null);
this.add(getPdpAccountDate(), null);
this.add(getPopOperator(), null);
this.add(getComboBillState(), null);
}
public Class getServiceIntfClass()
{
return IInInventoryBillDAO.class;
}
protected Class getTableDataClass()
{
return InInventoryBillDetailInfo.class;
}
protected String getTableDataProperty()
{
return "details";
}
/**
* This method initializes cbIsRedBill
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getCbIsRedBill()
{
if (cbIsRedBill == null)
{
cbIsRedBill = new JCheckBox();
cbIsRedBill.setBounds(new Rectangle(221, 80, 80, 21));
cbIsRedBill.setEnabled(false);
cbIsRedBill.setText("是否红单");
}
return cbIsRedBill;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setSize(new Dimension(403, 46));
jScrollPane.setViewportView(getTxtDesc());
jScrollPane.setLocation(new Point(10, 143));
}
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 getPdpInDate()
{
if (pdpInDate == null)
{
pdpInDate = new PopupDatePicker();
pdpInDate.setBounds(new Rectangle(76, 45, 120, 21));
}
return pdpInDate;
}
/**
* 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(291, 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(342, 79, 69, 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;
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -