package nc.ui.pu.m25.editor.card.beforeedit.body;

import nc.ui.bd.ref.model.StorDocReportRefModel;
import nc.ui.pu.pub.editor.card.listener.ICardBodyBeforeEditEventListener;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pubapp.uif2app.event.card.CardBodyBeforeEditEvent;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.SqlBuilder;

public class OcrRefbf  implements ICardBodyBeforeEditEventListener {

	@Override
	public void beforeEdit(CardBodyBeforeEditEvent cardbodybeforeeditevent) {
		BillCardPanel cpanel=cardbodybeforeeditevent.getBillCardPanel();
		Object objvdef17=cpanel.getHeadItem("vdef17").getValueObject();//附件id
		UIRefPane ref=(UIRefPane) cpanel.getBodyItem("OCR").getComponent();
		ref.setMultiSelectedEnabled(false);
		ref.setNotLeafSelectedEnabled(false);
		StorDocReportRefModel storef=(StorDocReportRefModel) ref.getRefModel();
		if(objvdef17 == null || "".equals(objvdef17)){
			ExceptionUtils.wrappBusinessException("请添加发票！");
		}
		Object pk_supplier  = cpanel.getHeadItem("pk_supplier").getValueObject();//供应商
		if(pk_supplier == null) {
			ExceptionUtils.wrappBusinessException("请先选择供应商！");
		}
		String pk_material = (String) cpanel.getBodyValueAt(cardbodybeforeeditevent.getRow(), "pk_material");
		if(pk_material == null) {
			ExceptionUtils.wrappBusinessException("请先选择物料！");
		}
		
		int count=cpanel.getRowCount();
		String vbdef20 = "";
		for(int i=0;i<count;i++){
			int ix=cardbodybeforeeditevent.getRow();
			String str = (String) cpanel.getBodyValueAt(i, "vbdef20");
			//当前行数据不需要过滤
			if(i != ix && str != null) {
				vbdef20 += str +",";
			}
		}
		storef.addWherePart(" and name6='"+objvdef17.toString()+"' "); //附件主键过滤
		if(!"".equals(vbdef20)) {
			String[] arrVbdef20 = vbdef20.split(",");
			if(arrVbdef20.length == 1) {
				storef.addWherePart(" and name6='"+objvdef17.toString()+"' and pk_defdoc <> '"+arrVbdef20[0].toString()+"'");
			}else {
				SqlBuilder sqlb = new SqlBuilder();
				sqlb.append("not", arrVbdef20);
				storef.addWherePart("and name6='"+objvdef17.toString()+"' and pk_defdoc "+sqlb.toString());
			}
			
		}
		
	}

}
