package baseclass;

import p2.pao.PaoSetRemote;
import p2.util.P2Exception;
import p2.webclient.system.beans.MultiselectDataBean;
import p2.webclient.system.controller.Utility;
import p2.webclient.system.controller.WebClientEvent;

/**
 * 博远自定义的ByMultiselectDataBean类，继承MultiselectDataBean类
 *
 * @author Administrator
 */
public class MultiselectDataBeanCust extends MultiselectDataBean {
    /**
     * 用于打开选择对话框后，进行过滤已添加信息的方法。
     *
     * @param remote 表体paoset
     * @param arg1   表体paoset对应栏位名
     * @param arg2   对话框paoset对应栏位名
     * @return 返回“ 1=1 and agrs1!=value1 and agrs2!=value2....”的字符串
     * @throws P2Exception
     */
    public String getworlds(PaoSetRemote remote, String arg1, String arg2) throws P2Exception {
        StringBuilder a = new StringBuilder(" 1=1 ");
        int i = 0;
        while (remote.getPao(i) != null) {
            String arg3 = remote.getPao(i).getString(arg1);
            a.append(" and ").append(arg2).append("!= '").append(arg3).append("'");
            i++;
        }
        return a.toString();
    }

    public String getworlds(PaoSetRemote remote, String[] arg1, String[] arg2) throws P2Exception {
        String a = " 1=1 ";
        StringBuilder e = new StringBuilder(" '' ");
        StringBuilder c = new StringBuilder(" '%$' ");
        for (String fields2 : arg2) {
            e.append("+ convert(varchar(50),").append(fields2).append(")");
        }
        int i = 0;
        while (remote.getPao(i) != null) {
            StringBuilder d = new StringBuilder();
            for (String fields : arg1) {
                d.append(remote.getPao(i).getString(fields));
            }
            c.append(",'").append(d).append("'");

            i++;
        }
        a = a + " and " + e + " not in(" + c + ")";

        return a;
    }

    @Override
    public synchronized void selectAll() throws P2Exception {
        super.selectAll();
//        if (count() <= 100 || "PRICEADJ".equalsIgnoreCase(agentclient.getApp()) || "SALECLASS".equalsIgnoreCase(agentclient.getApp())
//                || "TAGENT".equalsIgnoreCase(agentclient.getApp())) {
//            super.selectAll();
//        } else {
//            int StartIndex = this.getPageStartIndex();// 开始行
//            boolean iselect = !this.isSelected(StartIndex);
//            int EndIndex = this.getPageRowCount();// 结束行
//            if (iselect) {
//                this.select(StartIndex, EndIndex);
//            } else {
//                this.unselect(StartIndex, EndIndex);
//            }
//            this.refreshTable();
//            sessionContext.queueRefreshEvent();
//        }
    }

    @Override
    public synchronized void unselectAll() throws P2Exception {
        super.unselectAll();
//        if (count() <= 100 || "PRICEADJ".equalsIgnoreCase(agentclient.getApp()) || "SALECLASS".equalsIgnoreCase(agentclient.getApp())
//                || "TAGENT".equalsIgnoreCase(agentclient.getApp())) {
//            super.unselectAll();
//        } else {
//            int StartIndex = this.getPageStartIndex();// 开始行
//            boolean iselect = !this.isSelected(StartIndex);
//            int EndIndex = this.getPageRowCount();// 结束行
//            if (iselect) {
//                this.select(StartIndex, EndIndex);
//            } else {
//                this.unselect(StartIndex, EndIndex);
//            }
//            this.refreshTable();
//            sessionContext.queueRefreshEvent();
//        }
    }

    public void closeApp(String closeApp) throws P2Exception {
        Utility.sendEvent(new WebClientEvent("closeappwin", app.getApp().toLowerCase(),
                closeApp, "", "", 0, sessionContext));
    }

    public void openApp(String openApp, long fbillid) throws P2Exception {
        closeApp(openApp);
        Utility.sendEvent(new WebClientEvent("opennewapp", app.getApp().toLowerCase(),
                openApp, "", "", fbillid, sessionContext));
    }
    @Override
    public int callMethod(WebClientEvent webClientEvent) throws P2Exception {
        super.callMethod(webClientEvent);
        this.app.getAppBean().save();
        return 1;
    }
}
