使用按钮触发、按钮Action的代码
package nc.ui.hsw.actions;import java.awt.event.ActionEvent;import nc.ui.hsw.show.windows.SplitLineDialogNew;import nc.ui.hsw.show.windows.SplitLineDialog;import nc.ui.pu.m23.view.ArriveCardForm;import nc.ui.pub.beans.MessageDialog;import nc.ui.so.salequotation.model.SalequoModel;import nc.ui.so.salequotation.view.SalequoBillForm;import nc.ui.uif2.NCAction;import nc.vo.pubapp.pattern.exception.ExceptionUtils;import nc.vo.so.salequotation.entity.SalequotationBVO;public class XSBJDbuttonAction extends NCAction{ private final String btncode = "PUSH_FX"; private final String btnname = "代替品"; private SalequoModel model; private ArriveCardForm form; private SalequoBillForm billForm; @Override public void doAction(ActionEvent arg0) throws Exception { int[] srow = null; SalequotationBVO bvo =null; // TODO 自动生成的方法存根 srow = this.getBillForm().getBillCardPanel().getBillTable() .getSelectedRows(); // 当前所选界面是卡片界面 if (srow == null || srow.length == 0) { //错误提示 ExceptionUtils.wrappBusinessException("请选一行到货单表体!"); return; } else if (srow.length > 1) { //错误提示 ExceptionUtils.wrappBusinessException("只能选一行到货单表体!"); return; } //this.getBillForm().getBillCardPanel().getBillData(); //form.getBillCardPanel().getBodyItems(); //获取当前选中的表体VO bvo = (SalequotationBVO) this.getBillForm().getBillCardPanel().getBillModel() .getBodyValueRowVO(srow[0], SalequotationBVO.class.getName()); if(null==bvo.getVbdef6()||"".equals(bvo.getVbdef6())){ //错误提示 MessageDialog.showErrorDlg(this.getBillForm(), "警告", "请先选择发货仓库再进行替代品选择!!"); return; } if(null==bvo.getNassistnum()||"".equals(bvo.getNassistnum())){ //错误提示 MessageDialog.showErrorDlg(this.getBillForm(), "警告", "请先填写数量再进行替代品选择!!"); return; } /*AbstractFunclet funclet = (AbstractFunclet) getModel().getContext() .getEntranceUI(); AggSalequotationHVO custVo=(AggSalequotationHVO) this.getModel().getSelectedData();*/ //创建弹出框的对象 SplitLineDialog dlg=new SplitLineDialog(this.getBillForm(),model); //初始化界面的数据 dlg.initData(srow[0],bvo); //展示界面 dlg.showModal(); } public XSBJDbuttonAction(){ this.setCode(btncode); this.setBtnName(btnname); } public SalequoModel getModel() { return model; } public void setModel(SalequoModel model) { this.model = model; } public SalequoBillForm getBillForm() { return billForm; } public void setBillForm(SalequoBillForm billForm) { this.billForm = billForm; }
}
弹出框的代码
package nc.ui.hsw.show.windows;import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.swing.JPanel;import nc.bs.dao.BaseDAO;import nc.bs.framework.common.NCLocator;import nc.itf.uap.IUAPQueryBS;import nc.jdbc.framework.processor.MapListProcessor;import nc.ui.dcm.chnlrplstrct.maintain.action.MessageDialog;import nc.ui.pub.beans.UIButton;import nc.ui.pub.beans.UIDialog;import nc.ui.pub.beans.UIPanel;import nc.ui.pub.bill.BillCardPanel;import nc.ui.pub.bill.BillEditEvent;import nc.ui.pub.bill.BillEditListener;import nc.ui.pub.bill.BillEditListener2;import nc.ui.pub.bill.BillItem;import nc.ui.so.salequotation.model.SalequoModel;import nc.ui.so.salequotation.view.SalequoBillForm;import nc.vo.hswrk.bd_materialrepl.Hswrk_materialrepl;import nc.vo.pub.BusinessException;import nc.vo.pub.lang.UFDouble;import nc.vo.so.salequotation.entity.AggSalequotationHVO;import nc.vo.so.salequotation.entity.SalequotationBVO;import nc.vo.so.salequotation.entity.SalequotationHVO;/** * * @ClassName: SplitLineDialog * @Description: TODO(拆行对话框) * @author TXK * @version 1.0 */ public class SplitLineDialogNew extends UIDialog implements BillEditListener, BillEditListener2 { private static final long serialVersionUID = 5064747027574608058L; private BillCardPanel parent; /** UI JPanel */ private JPanel uiContentPane; /** 确定按钮 */ private UIButton btnOK; /** 增行按钮 */ private UIButton btnAddLine; /** 删行按钮 */ private UIButton btnDelLine; /** 按钮响应事件 */ private ActionHandler actionHandler = new ActionHandler(); /** 按钮模板 */ private UIPanel btnUIPanel; private BillCardPanel billPanel; // 生产计划编制选择的表体行 private int row = -1; // 生产计划编制选择 的表体行vo private SalequotationBVO curBody = null; private BaseDAO dao; //数据源 private static IUAPQueryBS query; private SalequoModel model; private SalequoBillForm billForm; public SplitLineDialogNew(SalequoBillForm billForm,SalequoModel model) { super(billForm.getBillCardPanel()); this.parent = billForm.getBillCardPanel(); this.billForm = billForm; this.model=model; this.initialize(); } /** * 初始化界面数据 * @param row * @param body */ public void initData(int row, SalequotationBVO body) { if (body == null) { return; } this.row = row; this.curBody = body; //获取当前选中行的主键 String pk_material = body.getPk_material(); //获取组织 String pk_org = body.getPk_org(); //获取发货仓库 String pk_tardoc = body.getVbdef6(); List reault = null; try { //查询当前物料的替代品 String materialrepsql = "select re.*,ma.NAME,ma.version,ma.code from bd_materialrepl re left join bd_material ma on re.PK_REPLACE=ma.PK_MATERIAL "+ "where re.PK_MATERIAL='"+pk_material+"'"; reault=(List) getQuery().executeQuery(materialrepsql,new MapListProcessor()); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } for(int i=0;i<reault.size();i++){ HashMap map = (HashMap) reault.get(i); String nonhandnumSql = "select sum(nonhandnum) from ic_onhanddim icim left join ic_onhandnum icom on icim.pk_onhanddim=icom.pk_onhanddim where " +"cwarehouseid= '"+pk_tardoc+"' and cmaterialvid= '"+String.valueOf(map.get("pk_replace"))+"'"; Map map1 = getMapBySql(nonhandnumSql);//现存量 String num = String.valueOf(0);//现存量 if(null!=map1){ num=String.valueOf(map.get("nonhandnum")==null?0:map.get("nonhandnum")); } String maSql ="select def4 from bd_material where pk_material ='"+String.valueOf(map.get("pk_replace"))+"'";//限购量查询 Map map2 = getMapBySql(maSql);//限购量 String num1 = String.valueOf(0);//限购量 if(null!=map2){ num1=String.valueOf(map2.get("def4")==null?0:map2.get("def4")); } // 创建VO Hswrk_materialrepl splivo = new Hswrk_materialrepl(); //给VO赋值 splivo.setSubstituterate(String.valueOf(map.get("substituterate"))); splivo.setPk_material(String.valueOf(map.get("pk_material"))); splivo.setPk_replace(String.valueOf(map.get("pk_replace"))); //splivo.setPk_replace("物料"); splivo.setPk_org(String.valueOf(map.get("pk_org"))); splivo.setReplaceorder((Integer) map.get("replaceorder")); splivo.setPk_materialplan(String.valueOf(map.get("pk_materialplan"))); splivo.setDef2(String.valueOf(map.get("code")));//物料编码 splivo.setDef3(String.valueOf(map.get("name")));//替换件名称 splivo.setDef4(String.valueOf(map.get("version")));//版本 splivo.setDef6(num);//现存量 splivo.setDef9(Integer.valueOf(num1));//限购量 /* if (!StringUtils.isEmpty(body.getVbdef4())) { splivo.setVbdef4(new UFDouble(body.getVbdef4())); } if (!StringUtils.isEmpty(body.getVbdef5())) { splivo.setVbdef5(new UFDouble(body.getVbdef5())); } if (!StringUtils.isEmpty(body.getVbdef6())) { splivo.setVbdef6(new UFDouble(body.getVbdef6())); } // 设置拆分界面表头数据 String[] names = splivo.getAttributeNames(); for (String name : names) { this.billPanel.setHeadItem(name, splivo.getAttributeValue(name)); } this.billPanel.setHeadItem("fis3", UFBoolean.TRUE); */ //在界面上创建一一行 this.billPanel.getBillModel().addLine(); //将VO放入节点当中 this.billPanel.getBillModel().setBodyRowVO(splivo, i); } /* CircularlyAccessibleValueObject[] tmpHeadVo =hcutVos.toArray(new CircularlyAccessibleValueObject[] {}); this.billPanel.getBillModel().setBodyRowVOs(tmpHeadVo,rows);*/ } /** * 通过查询获取map * @param sql * @return */ private Map getMapBySql(String sql){ Map map =null; try { List list= (List) getQuery().executeQuery(sql,new MapListProcessor()); if(null!=list&&list.size()>0){ map=(Map) list.get(0); } } catch (BusinessException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return map; } /** * 设置界面元素 */ private void initialize() { this.setName("mpsSplitDialog"); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setTitle("代替品物料信息"); //界面宽度 int w = 1000; //界面高度 int h = 600; this.setBounds(500, 400, w, h); this.setResizable(true); // 设置模板 this.setContentPane(this.getUIContentPane()); // 添加监听 this.addActionListener(); } /** * 界面的监听 */ private void addActionListener() { // TODO Auto-generated method stub // this.getBtnAddLine().addActionListener(this.actionHandler); this.getBtnDelLine().addActionListener(this.actionHandler); this.getBtnOK().addActionListener(this.actionHandler); } /** * 界面UI组装 * @return */ private Container getUIContentPane() { if (null == this.uiContentPane) { this.uiContentPane = new JPanel(); this.uiContentPane.setName("UIDialogContentPane"); this.uiContentPane.setLayout(new BorderLayout()); this.getUIContentPane().add(this.getBillPanel(), "Center"); this.getUIContentPane().add(this.getBtnUIPanel(), "South"); } return this.uiContentPane; } /** * 获取节点 * @return */ private BillCardPanel getBillPanel() { // TODO Auto-generated method stub if (this.billPanel == null) { this.billPanel = new BillCardPanel(); this.billPanel.setName("mpsSplitPanel"); //加载节点传节点的主键 this.billPanel.loadTemplet("0001ZZ100000000052W6"); this.billPanel.addEditListener(this); this.billPanel.addBillEditListenerHeadTail(this); this.billPanel.getBillTable().setSelectionMode( javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.billPanel.setTatolRowShow(false); this.billPanel.setBodyMenuShow(false); } return this.billPanel; } /** * 按钮pannelgetter * * @return 按钮pannel */ public UIPanel getBtnUIPanel() { if (this.btnUIPanel == null) { this.btnUIPanel = new nc.ui.pub.beans.UIPanel(); this.btnUIPanel.setName("BtnUIPanel"); /* this.btnUIPanel.add(this.getBtnAddLine(), this.getBtnAddLine() .getName()); */ this.btnUIPanel.add(this.getBtnDelLine(), this.getBtnDelLine() .getName()); this.btnUIPanel.add(this.getBtnOK(), this.getBtnOK().getName()); } return this.btnUIPanel; } /** * 初始化确定按钮 */ private UIButton getBtnOK() { if (null == this.btnOK) { this.btnOK = new UIButton(); this.btnOK.setName("btnOK"); this.btnOK.setText("确定"); } return this.btnOK; } /** * 给取消按钮赋值 * @return */ private UIButton getBtnDelLine() { if (null == this.btnDelLine) { this.btnDelLine = new UIButton(); this.btnDelLine.setName("btnDelLine"); this.btnDelLine.setText("取消"); } return this.btnDelLine; } /* private UIButton getBtnAddLine() { if (null == this.btnAddLine) { this.btnAddLine = new UIButton(); this.btnAddLine.setName("btnAddLine"); this.btnAddLine.setText("增行"); } return this.btnAddLine; } */ @Override public boolean beforeEdit(BillEditEvent e) { // TODO Auto-generated method stub return true; } @Override public void afterEdit(BillEditEvent e) { // TODO Auto-generated method stub int row = e.getRow(); String key = e.getKey(); Object value = e.getValue(); if (e.getPos() == BillItem.HEAD) { } else if (e.getPos() == BillItem.BODY) { // 当前表头和表体的数量型的字段,完全一致 if (value instanceof UFDouble) { UFDouble u_value = (UFDouble) value; UFDouble hu_value = (UFDouble) this.billPanel.getHeadItem(key) .getValueObject(); if (hu_value == null || hu_value.doubleValue() == 0) { this.billPanel.setBodyValueAt(null, row, key); } UFDouble rate = u_value.div(hu_value); updateRowNum(rate, row); } } } private void updateRowNum(UFDouble rate, int row) { // TODO Auto-generated method stub Boolean fis3 = (Boolean) this.billPanel.getHeadItem("fis3") .getValueObject(); String[] update_keys = new String[] { "tnum", "tnastnum", "fnum", "fnastnum", "num", "nastnum" }; if (fis3 == null || !fis3) { // 如果不联动3类 update_keys = new String[] { "fnum", "fnastnum", "num", "nastnum" }; } for (String key : update_keys) { UFDouble hu_value = (UFDouble) this.billPanel.getHeadItem(key) .getValueObject(); if (hu_value == null || hu_value.doubleValue() == 0) { continue; } UFDouble bu_value = hu_value.multiply(rate); this.billPanel.setBodyValueAt(bu_value, row, key); } } @Override public void bodyRowChange(BillEditEvent e) { // TODO Auto-generated method stub } class ActionHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == SplitLineDialogNew.this.getBtnOK()) { // 确定按钮执行事件 SplitLineDialogNew.this.doOKAction(); } /* if (e.getSource() == SplitLineDialog.this.getBtnAddLine()) { // 增行 SplitLineDialog.this.doAddLineAction(); } */ if (e.getSource() == SplitLineDialogNew.this.getBtnDelLine()) { //取消执行的事件 SplitLineDialogNew.this.closeCancel(); /* // 删除行 int[] selectRows = getBillPanel().getBillTable() .getSelectedRows(); List<Integer> rows = new ArrayList<Integer>(); for (int row : selectRows) { String crwono = (String) getBillPanel().getBodyValueAt(row, "crowno"); if (!StringUtils.isEmpty(crwono)) { // 原始的行,不能删除掉 continue; } rows.add(row); } if (rows.size() == 0) { return; } int[] delete_row = new int[rows.size()]; for (int i = 0; i < delete_row.length; i++) { delete_row[i] = rows.get(i); } getBillPanel().getBillModel().delLine(delete_row); */ } } } private void doAddLineAction() { // TODO Auto-generated method stub getBillPanel().getBillModel().addLine(); int rowCount = getBillPanel().getBillModel().getRowCount(); Object vbdef4 = getBillPanel().getHeadItem("vbdef4").getValueObject(); Object vbdef5 = getBillPanel().getHeadItem("vbdef5").getValueObject(); Object vbdef6 = getBillPanel().getHeadItem("vbdef6").getValueObject(); getBillPanel().setBodyValueAt(vbdef4, rowCount - 1, "vbdef4"); getBillPanel().setBodyValueAt(vbdef5, rowCount - 1, "vbdef5"); getBillPanel().setBodyValueAt(vbdef6, rowCount - 1, "vbdef6"); } private void doOKAction() { //获取弹框中的vo Hswrk_materialrepl[] bodys = (Hswrk_materialrepl[]) getBillPanel() .getBillModel().getBodyValueVOs(Hswrk_materialrepl.class.getName()); List<Hswrk_materialrepl> bodylist = new ArrayList<Hswrk_materialrepl>(); for(int i=0;i<bodys.length;i++){ Hswrk_materialrepl hswrk_materialrepl = bodys[i]; //String chess = hswrk_materialrepl.getDef11() //判断数据是否被选中 if(hswrk_materialrepl.getDef11().booleanValue()){ bodylist.add(hswrk_materialrepl); } } if(bodylist.size()==1){ //获取节点的AGGVO AggSalequotationHVO aggvo = (AggSalequotationHVO) this.billForm.getValue(); //新创建一个节点的AGGVO AggSalequotationHVO newaggvo = new AggSalequotationHVO(); //获取节点的表头VO SalequotationHVO headvo = aggvo.getParentVO(); //给选中的行VO 重新赋值 this.curBody.setPk_material_v(bodylist.get(0).getPk_replace());//物料 this.curBody.setVbdef1(bodylist.get(0).getDef5());//交期 this.curBody.setVbdef2(bodylist.get(0).getDef6());//可用量 this.curBody.setVbdef5(String.valueOf(bodylist.get(0).getDef9()));//限购量 //this.curBody.setNassistnum(new UFDouble("20")); //获取界面表体VO的集合 SalequotationBVO[] bvos= aggvo.getChildrenVO(); //创建新的表体VO的集合 SalequotationBVO[] newbvos = new SalequotationBVO[bvos.length]; for(int i=0;i<bvos.length;i++){ SalequotationBVO bvo = bvos[i]; //判断是不是当前选中的VO if(!bvo.getCrowno().equals(this.curBody.getCrowno())){ //给新的表体VO的集合赋值 newbvos[i]=bvo; }else{ newbvos[i]=this.curBody; } } //将新的表体VO的集合放入到AGGVO中 newaggvo.setChildrenVO(newbvos); //将表头VO放入到AGGVO中 newaggvo.setParentVO(headvo); //将AGGVO付给节点 this.parent.setBillValueVO(newaggvo); //关闭弹出的窗口 this.parent.getBillModel().loadLoadRelationItemValue(); this.closeOK(); }else if(bodylist.size()>1){ //弹出提示框 MessageDialog.showErrorDlg(this.parent, null, "不能选择多个替代品"); }else{ //弹出提示框 MessageDialog.showErrorDlg(this.parent, null, "需要选中一行"); } } public SalequoModel getModel() { return model; } public void setModel(SalequoModel model) { this.model = model; }private BaseDAO getDao(){ if(null==dao){ dao=new BaseDAO(); } return dao; }private IUAPQueryBS getQuery(){ if (query == null) { query = (IUAPQueryBS)NCLocator.getInstance().lookup( IUAPQueryBS.class.getName()); } return query;}}
