1.单据上增加按钮
package nc.ui.ic.dpfp.action;
import java.awt.event.ActionEvent;
import java.util.List;
import nc.cmp.utils.Lists;
import nc.ui.ref.model.IcOnhandnumRefModel;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.model.AbstractAppModel;
import nc.ui.pubapp.uif2app.view.BillForm;
import nc.vo.ic.dpfp.OnhandNumVO;
public class SearchXyl extends nc.ui.pubapp.uif2app.actions.AddAction{
private AbstractAppModel model;
private BillForm editor;
public SearchXyl(){
setBtnName("现有量");
setCode("SearchXyl");
putValue("SearchXyl", "现有量");
}
@Override
public void doAction(ActionEvent arg0) throws Exception {
// TODO Auto-generated method stub
// 创建弹出框的对象
IcOnhandnumDig panel = new IcOnhandnumDig(getModel().getContext().getEntranceUI());
panel.setModel(getModel());
panel.setValue(null);
panel.setFromval(null);
panel.setEditor(getEditor());
// panel.setEditor(getModel());
panel.initUI();
panel.showModal();
}
public AbstractAppModel getModel() {
return model;
}
public void setModel(AbstractAppModel model) {
this.model = model;
}
public BillForm getEditor() {
return editor;
}
public void setEditor(BillForm editor) {
this.editor = editor;
}
}
2.自定义弹窗类
package nc.ui.ic.dpfp.action;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.util.List;
import java.util.Vector;
import javax.swing.ListSelectionModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentListener;
import java.awt.event.ItemEvent;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.cmp.utils.Lists;
import nc.itf.ic.IDpfpMaintain;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.uif2.UIState;
import nc.ui.uif2.model.AbstractAppModel;
import nc.ui.pubapp.uif2app.view.BillForm;
import nc.vo.bd.material.marbasclass.MarBasClassVO;
import nc.vo.ic.dpfp.DpfpBVO;
import nc.vo.ic.dpfp.DpfpBillVO;
import nc.vo.ic.dpfp.DpfpHVO;
import nc.vo.ic.dpfp.OnhandNumVO;
import nc.vo.scmf.ic.mbatchcode.BatchcodeVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.ui.bd.datadetect.view.ButtonUtils;
import nc.ui.bd.ref.AbstractRefModel;
import nc.ui.cdm.report.uicommon.ControlsListener;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UILabel;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.beans.UITable;
import nc.ui.pub.beans.ValueChangedEvent;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@SuppressWarnings("restriction")
public class IcOnhandnumDig extends UtilDialog implements ControlsListener , ActionListener{
protected AbstractAppModel model = null;
private Object value;
private BillForm editor;
private UIPanel refPanel;
private UIPanel mainPanel;
private UIRefPane refPanelZZ;
private UIRefPane refPanelCK;
private UIRefPane refPanelWL;
private UIRefPane refPanelWLFL;
private UIButton search;//查询
private String[] fromval;
private UITable table; //表格
private JScrollPane scrollPane;
private DefaultTableModel tableModel;
private UILabel wpv;
private String pk_org = "";
private String pk_stordoc = "";
private String pk_material = "";
private String pk_marbasclass = "1001A11000000000NE0J";
public IcOnhandnumDig(Container parent) {
super(parent,false);
// TODO 自动生成的构造函数存根
}
@Override
protected JComponent createCenterPanel() {
return getMainPanel();
}
@Override
public void closeOK() {
IDpfpMaintain proxy=NCLocator.getInstance().lookup(IDpfpMaintain.class);
int[] rows = table.getSelectedRows();
OrgVO vo = (OrgVO) proxy.getDataByPk(pk_org, OrgVO.class);
DpfpHVO hvo = new DpfpHVO();
hvo.setPk_org(pk_org);
hvo.setPk_org_v(vo.getPk_vid());
hvo.setDbilldate(new UFDate());
hvo.setPk_group(vo.getPk_group());
hvo.setFstatusflag(-1);
List<DpfpBVO> listbvos = Lists.newArrayList();
for (int i = 0 ; i < rows.length ; i ++) {
if(StringUtils.isEmpty(tableModel.getValueAt(i, 8).toString())){
MessageDialog.showErrorDlg(null, "系统提示", "不能选择批次号为空的数据,请重新选择!");
break;
}
DpfpBVO bvo = new DpfpBVO();
bvo.setCrowno(i*10+"");
bvo.setCbodywarehouseid(tableModel.getValueAt(i, 12).toString());
bvo.setCmaterialvid(tableModel.getValueAt(i, 13).toString());
bvo.setVbatchcode(tableModel.getValueAt(i, 8).toString());
bvo.setPk_batchcode(tableModel.getValueAt(i, 14).toString());
bvo.setNum(new UFDouble(tableModel.getValueAt(i, 7).toString()));
if(tableModel.getValueAt(i, 15)!=null){
bvo.setBdef1(tableModel.getValueAt(i, 15).toString());
}
if(tableModel.getValueAt(i, 16)!=null){
bvo.setDishes(tableModel.getValueAt(i, 16).toString());
}
String newvbatchcode = "";
//分盘批次号
List<BatchcodeVO> listbatch = proxy.getDataBySql("select * from scm_batchcode where vbatchcode like '"+bvo.getVbatchcode()+"%' and dr=0 order by vbatchcode desc", BatchcodeVO.class);
if(CollectionUtils.isNotEmpty(listbatch)){
String vbatchcode = listbatch.get(0).getVbatchcode();
if(StringUtils.contains(vbatchcode, "-")){
String no = vbatchcode.substring(vbatchcode.lastIndexOf("-")+1,vbatchcode.length());
newvbatchcode = vbatchcode.substring(0,vbatchcode.lastIndexOf("-"))+"-"+(Integer.parseInt(no)+1);
}else{
newvbatchcode = vbatchcode +"-1";
}
}
bvo.setBdef2("0"); //来源类型 0 :自制、1:销售订单。2:调拨订单
bvo.setPk_org(pk_org);
bvo.setPk_org_v(vo.getPk_vid());
bvo.setPk_group(vo.getPk_group());
bvo.setFpvbatchcode(newvbatchcode);
//end
listbvos.add(bvo);
}
DpfpBVO[] bvos = listbvos.toArray(new DpfpBVO[listbvos.size()]);
DpfpBillVO aggvo = new DpfpBillVO();
aggvo.setParentVO(hvo);
aggvo.setChildrenVO(bvos);
getEditor().setValue(aggvo);
getEditor().setBodyStatusNew();
getModel().setOtherUiState(UIState.ADD);
super.closeOK();
}
private UIPanel getMainPanel() {
if (mainPanel == null) {
mainPanel = new UIPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(getRefPanel(), BorderLayout.CENTER);
setSize(1080, 750);
setResizable(false);
setTitle("选择数据");
}
return mainPanel;
}
public static UFDate getUFDate(Object value){
if (value == null || value.toString().trim().equals("")) {
return null;
}else if(value instanceof UFDate){
return (UFDate) value;
}else{
return new UFDate(value.toString().trim());
}
}
private BaseDAO dao;
private BaseDAO getBaseDao() {
if (dao == null) {
dao = new BaseDAO();
}
return dao;
}
public UIPanel getRefPanel(){
try {
if(this.refPanel == null){
refPanel = new UIPanel();
refPanel.setLayout(null);
//订单信息
UILabel code = new UILabel("组织:");
code.setBounds(10, 5, 80, 50);
refPanel.add(code);
refPanel.add(getRefPanelZZ());
//仓库
UILabel ck = new UILabel("仓库:");
ck.setBounds(250, 5, 80, 50);
refPanel.add(ck);
refPanel.add(getRefPanelCK());
//物料
UILabel wl = new UILabel("物料:");
wl.setBounds(490, 5, 80, 50);
refPanel.add(wl);
refPanel.add(getRefPanelWL());
//物料
UILabel wlfl = new UILabel("物料分类:");
wlfl.setBounds(730, 5, 80, 50);
refPanel.add(wlfl);
refPanel.add(getRefPanelWLFL());
refPanel.add(getSearch());
Vector<Vector<String>> tableValues = new Vector<>();
refPanel.add(getTable(tableValues));
}
return refPanel;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
private JScrollPane getTable(Vector<Vector<String>> tableValues){
if(scrollPane == null){
//设置UITable中的列名
Vector<String> columnNames = new Vector<>();
columnNames.add("库存组织");
columnNames.add("仓库");
columnNames.add("物料代码");
columnNames.add("物料名称");
columnNames.add("型号");
columnNames.add("规格");
columnNames.add("颜色");
columnNames.add("数量");
columnNames.add("批号");
columnNames.add("盘具名称");
columnNames.add("盘具分类");
columnNames.add("盘具规格");
columnNames.add(""); //仓库
columnNames.add(""); //物料
columnNames.add(""); //批次
columnNames.add(""); //颜色
columnNames.add(""); //盘具pk
if(table == null){
this.tableModel = new DefaultTableModel(tableValues, columnNames);
// 添加JLabel组件
table = new UITable(this.tableModel);
// table.setBounds(380, 20, 120, 450);
// table.setSize(350, 330);
table.setEnabled(true);
table.getColumnModel().getColumn(0).setPreferredWidth(120);
table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setPreferredWidth(120);
table.getColumnModel().getColumn(3).setPreferredWidth(120);
table.getColumnModel().getColumn(4).setPreferredWidth(120);
table.getColumnModel().getColumn(5).setPreferredWidth(120);
table.getColumnModel().getColumn(6).setPreferredWidth(120);
table.getColumnModel().getColumn(7).setPreferredWidth(120);
table.getColumnModel().getColumn(8).setPreferredWidth(120);
table.getColumnModel().getColumn(9).setPreferredWidth(120);
table.getColumnModel().getColumn(10).setPreferredWidth(120);
table.getColumnModel().getColumn(11).setPreferredWidth(120);
table.getTableHeader().getColumnModel().getColumn(12).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(13).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(14).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(15).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(16).setMaxWidth(0);
//
// table.removeColumn(table.getColumnModel().getColumn(12));
// table.removeColumn(table.getColumnModel().getColumn(13));
// table.removeColumn(table.getColumnModel().getColumn(14));
// table.removeColumn(table.getColumnModel().getColumn(15));
// table.removeColumn(table.getColumnModel().getColumn(16));
table.setPreferredScrollableViewportSize(new Dimension(400, 20));
table.getTableHeader().setReorderingAllowed(true);
table.getTableHeader().setVisible(true);
// table.scrollRectToVisible(getBounds());
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setAutoResizeMode(UITable.AUTO_RESIZE_OFF);
table.setBorder(BorderFactory.createEtchedBorder());
// UICheckBox cbox = new UICheckBox();
// table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(cbox));
scrollPane = new JScrollPane(table);
// scrollPane.setSize(350, 330);
scrollPane.setBounds(5, 50, 1070, 660);
}
}
return scrollPane;
}
public AbstractAppModel getModel() {
return model;
}
public void setModel(AbstractAppModel model) {
this.model = model;
}
@Override
public void valueChanged(ValueChangedEvent arg0) {
// TODO Auto-generated method stub
if(refPanelZZ!=null){
if(refPanelZZ.getValueObj()!=null){
pk_org = refPanelZZ.getRefPK();
AbstractRefModel model = refPanelCK.getRefModel();
model.addFilterRefWherePart("库存组织", "pk_org='"+pk_org+"'");
model.setPk_org(pk_org);
}
}
if(refPanelCK!=null){
if(refPanelCK.getValueObj()!=null){
pk_stordoc = refPanelCK.getRefPK();
}
}
if(refPanelWL!=null){
if(refPanelWL.getValueObj()!=null){
pk_material = refPanelWL.getRefPK();
}
}
if(refPanelWLFL!=null){
if(refPanelWLFL.getValueObj()!=null){
pk_marbasclass = refPanelWLFL.getRefPK();
}
}
}
@Override
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
private UIRefPane createRefPaneByNodeName(String nodeName, UIRefPane refPanel)
{
if(refPanel == null)
{
refPanel = new UIRefPane();
refPanel.setRefNodeName(nodeName);
refPanel.setBounds(90, 142, 60, 50);
refPanel.setSize(250, 30);
refPanel.setPreferredSize(new java.awt.Dimension(222, 22));
refPanel.setSize(new java.awt.Dimension(222, 22));
refPanel.addValueChangedListener(this);
refPanel.setMultiSelectedEnabled(false); //可在addControlsToUI()实现中重设之 设置单选-多选
// if(nodeName.equals("现金银行账户") || nodeName.equals("银行账户使用权"))
if(nodeName.equals("仓库") ){/*-=notranslate=-*/
AbstractRefModel model = refPanel.getRefModel();
model.addFilterRefWherePart("库存组织", "pk_org='"+pk_org+"'");
model.setPk_org(pk_org);
// refPanel.getRefModel().setSealedDataShow(true);
// refPanel.getRefModel().setAddEnvWherePart(false);
}
}
return refPanel;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public UIRefPane getRefPanelZZ() {
refPanelZZ = createRefPaneByNodeName("库存组织", refPanelZZ);/*-=notranslate=-*/
refPanelZZ.setBounds(60, 18, 60, 50);
refPanelZZ.setSize(160, 30);
refPanelZZ.getUITextField().addActionListener(this);
pk_org = getEditor().getBillCardPanel().getHeadItem("pk_org").getValue();
refPanelZZ.setValueObj(pk_org); //默认3:产成品 分类
refPanelZZ.setPK(pk_org);
refPanelZZ.setValue(pk_org);
return refPanelZZ;
}
public UIRefPane getRefPanelCK() {
refPanelCK = createRefPaneByNodeName("仓库", refPanelCK);/*-=notranslate=-*/
refPanelCK.setBounds(300, 18, 60, 50);
refPanelCK.setSize(160, 30);
refPanelCK.getUITextField().addActionListener(this);
return refPanelCK;
}
public UIRefPane getRefPanelWL() {
refPanelWL = createRefPaneByNodeName("物料", refPanelWL);/*-=notranslate=-*/
refPanelWL.setBounds(540, 18, 60, 50);
refPanelWL.setSize(160, 30);
refPanelWL.getUITextField().addActionListener(this);
return refPanelWL;
}
public UIRefPane getRefPanelWLFL() {
refPanelWLFL = createRefPaneByNodeName("物料基本分类", refPanelWLFL);/*-=notranslate=-*/
refPanelWLFL.setBounds(800, 18, 60, 50);
refPanelWLFL.setSize(160, 30);
refPanelWLFL.getUITextField().addActionListener(this);
refPanelWLFL.setValueObj("1001A11000000000NE0J"); //默认3:产成品 分类
refPanelWLFL.setText("3");
refPanelWLFL.setPK("1001A11000000000NE0J");
refPanelWLFL.setValue("1001A11000000000NE0J");
return refPanelWLFL;
}
public UIButton getSearch() {
if(search == null){
search = ButtonUtils.createButton("查询");
search.setBounds(1000, 16, 60, 50);
search.setSize(50, 30);
search.addActionListener(this);
}
return search;
}
public BillForm getEditor() {
return editor;
}
public void setEditor(BillForm editor) {
this.editor = editor;
}
public String[] getFromval() {
return fromval;
}
public void setFromval(String[] fromval) {
this.fromval = fromval;
}
@Override
public void actionPerformed(ActionEvent evt)
{
// if (evt.getActionCommand()!=null&&refPanelZZ.getValueObj()!=null)
// {
// if(evt.getActionCommand().equals(refPanelZZ.getValueObj().toString())){
// Object zz = refPanelZZ.getValueObj().toString(); //组织
// getRefPanelCK().getRefModel().addWherePart("pk_org='"+zz.toString()+"'");
// }
// }
if (evt.getSource() == search )
{
addcol();
}
if (evt.getSource() == btnCancel || evt.getSource() == btnClose)
{
closeCancel();
}
else if (evt.getSource() == btnOk)
{
closeOK();
}
}
@Override
public void addcol(){
int row = tableModel.getRowCount();
for (int i = 0 ; i< row; i ++) {
tableModel.removeRow(i);
}
Vector<Vector<String>> tableValues = new Vector<>();
String sql = "select * from VIEW_ONHANDNUM where pk_org ='"+pk_org+"'";
if(StringUtils.isNotEmpty(pk_stordoc)){
sql = sql+" and cwarehouseid='"+pk_stordoc+"'";
}
if(StringUtils.isNotEmpty(pk_material)){
sql = sql+" and cmaterialvid='"+pk_material+"'";
}
if(StringUtils.isNotEmpty(pk_marbasclass)){
IDpfpMaintain proxy=NCLocator.getInstance().lookup(IDpfpMaintain.class);
MarBasClassVO mvo = (MarBasClassVO) proxy.getDataByPk(pk_marbasclass, MarBasClassVO.class);
sql = sql+" and pk_marbasclass in (select pk_marbasclass from bd_marbasclass where innercode like '"+mvo.getInnercode()+"%')";
}
IDpfpMaintain main = NCLocator.getInstance().lookup(IDpfpMaintain.class);
List<OnhandNumVO> lists = main.getDataBySql(sql, OnhandNumVO.class);
for (OnhandNumVO vo : lists) {
Vector<String> rowV = new Vector<>();
rowV.add(vo.getOrgname());
rowV.add(vo.getStordocname());
rowV.add(vo.getCode());
rowV.add(vo.getName());
rowV.add(vo.getMaterialtype());
rowV.add(vo.getMaterialspec());
rowV.add(vo.getYs());
rowV.add(vo.getNonhandnum());
rowV.add(vo.getVbatchcode());
rowV.add(vo.getPjname());
rowV.add(vo.getPjclassname());
rowV.add(vo.getPjmaterialspec());
rowV.add(vo.getCwarehouseid());
rowV.add(vo.getCmaterialvid());
rowV.add(vo.getPk_batchcode());
rowV.add(vo.getVfree2());
rowV.add(vo.getPjpk());
tableModel.addRow(rowV);
}
}
}
3.实现效果