package sqlquery;

import java.util.Hashtable;

import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;
import p2.webclient.system.controller.Utility;
import p2.webclient.system.controller.WebClientEvent;
import baseclass.MultiselectDataBeanCust;

public class YlreportDialog extends MultiselectDataBeanCust {
	@Override
	protected PaoSetRemote getPaoSetRemote() throws P2Exception {
		PaoSetRemote paoSet = super.getPaoSetRemote();
		PaoRemote pao = app.getAppBean().getPao();
		if (pao != null) {
			String appname = app.getApp();
			String objectname = pao.getName();

			if (sessionContext.getCurrentApp().onListTab()) {
				paoSet.setWhere(" objectname='" + objectname
						+ "' and reporttype='报表' and (agentclient='" + appname
						+ "' or isnull(agentclient,'')='' )");
			} else {
				paoSet.setWhere(" objectname='" + objectname + "' and (agentclient='"
						+ appname + "' or isnull(agentclient,'')='' )");
			}
			paoSet.reset();
		}

		return paoSet;
	}

	@Override
	public int selectrecord() throws P2Exception {
		super.selectrecord();
		PaoRemote pao = getPao(getRowIndexFromEvent(sessionContext
				.getCurrentEvent()));

		Utility.sendEvent(sessionContext, app.getCurrentPageId(),
				"dialogclose", -1); // 客户端关闭对话框
		Hashtable<String, String> table = new Hashtable<String, String>(); // 保存打印信息的table
		String url = pao.getString("datatableiframeurl");
		String reporttype = pao.getString("reporttype");
		url = !"打印".equals(reporttype) ? url : url + "&"
				+ getPaoSet().getName() + "." + getUniqueIdName() + "="
				+ getUniqueIdValue();
		table.put("redir", url);
		Utility.sendEvent(new WebClientEvent("spawnreport", "reportd1320",
				table, this.sessionContext));
		return 1;
	}
}
