package configure;

import p2.pao.DBShortcutProvider;
import p2.pao.SqlFormat;
import p2.security.UserInfo;
import p2.util.P2Exception;

public class ConfigureAppBean extends p2.webclient.beans.configur.ConfigurBean {

	public int changeinternal() throws P2Exception {
		UserInfo userInfo = getPao().getUserInfo();
		DBShortcutProvider dbShortcut = new DBShortcutProvider();
		dbShortcut.connect(userInfo.getConnectionKey());
		String sqlstr = "update ps_sysobjects_df set internal=0 where objectname='"
				+ getString("objectname")
				+ "'and internal=1"
				+ "update ps_sysobjects set internal=0 where objectname='"
				+ getString("objectname") + "'and internal=1";
		String sqlstr2 = "update ps_sysobjects_df set internal=1 where objectname='"
				+ getString("objectname")
				+ "'and internal=0"
				+ "update ps_sysobjects set internal=1 where objectname='"
				+ getString("objectname") + "'and internal=0";
		if (!getBoolean("internal")) {
			sqlstr = sqlstr2;
		}
		try {
			SqlFormat sql = new SqlFormat(userInfo, sqlstr);
			dbShortcut.execute(sql);
			dbShortcut.commit();
			dbShortcut.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		this.reloadTable();
		this.refreshTable();
		this.sessionContext.queueRefreshEvent();
		return 1;
	}
}
