package p2.application.tpayinfo;

import baseclass.MultiselectDataBeanCust;
import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;
import p2.util.P2AppException;
import p2.util.P2Exception;
import p2.webclient.system.controller.Utility;
import p2.application.tenterprise.tenterprise;

import java.util.Iterator;

public class tpayinfoMlt extends MultiselectDataBeanCust {
    @Override
    protected PaoSetRemote getPaoSetRemote() throws P2Exception {
        PaoRemote pao = this.app.getAppBean().getPao();
        PaoSetRemote paoSet = super.getPaoSetRemote();// 获得对话框绑定物件
        if (pao != null) {
            if (!screenDesignMode) {
                if (this.app.getAppBean().getPao() != null) {
                    paoSet.setWhere("not exists(select *from tpayinfo where tpayinfo.tagentsid=tagents.tagentsid and convert(varchar(10),fbegdate,120)<=convert(varchar(10),getdate(),120) and convert(varchar(10),fenddate,120)>=convert(varchar(10),getdate(),120) )");
                    paoSet.reset();
                }
            }
        }
        return paoSet;
    }


    public int createagentpayinfo() throws P2Exception {
        PaoSetRemote tagentsSet = getPaoSet();
        Iterator<PaoRemote> it = tagentsSet.getSelection().iterator();
        String siteid = "";
        tenterprise tenterprise = null;
        while (it.hasNext()) {

            PaoRemote tagents = it.next();
            if (!siteid.equals("") && !siteid.equals(tagents.getString("siteid"))) {
                throw new P2AppException("", "一次只可选择一个站点的经销商");
            }
            siteid = tagents.getString("siteid");
            tenterprise = (tenterprise) tagents.getPaoSet("tenterprise").getPao(0);
        }

        if (tenterprise != null) {
            tenterprise.createdefaultpayinfovalidate(tagentsSet);
            tenterprise.createdefaultpayinfo(tagentsSet);
        }
        tagentsSet.save();
        Utility.sendEvent(sessionContext, app.getCurrentPageId(),
                "dialogclose", null);// 关闭当前对话框
        return 1;
    }

}
