text: /**
  	* \file PnlWdbeCmdMNController.cpp
  	* job handler for job PnlWdbeCmdMNController (implementation)
  	* \copyright (C) 2016-2020 MPSI Technologies GmbH
  	* \author Alexander Wirthmueller (auto-generation)
  	* \date created: 28 Nov 2020
  	*/
  // IP header --- ABOVE
  
  #ifdef WDBECMBD
  	#include <Wdbecmbd.h>
  #else
  	#include <Wdbed.h>
  #endif
  
  #include "PnlWdbeCmdMNController.h"
  
  #include "PnlWdbeCmdMNController_blks.cpp"
  #include "PnlWdbeCmdMNController_evals.cpp"
  
  using namespace std;
  using namespace Sbecore;
  using namespace Xmlio;
  
  // IP ns.cust --- INSERT
  
  /******************************************************************************
   class PnlWdbeCmdMNController
   ******************************************************************************/
  
  PnlWdbeCmdMNController::PnlWdbeCmdMNController(
  			XchgWdbe* xchg
  			, DbsWdbe* dbswdbe
  			, const ubigint jrefSup
  			, const uint ixWdbeVLocale
  		) :
  			JobWdbe(xchg, VecWdbeVJob::PNLWDBECMDMNCONTROLLER, jrefSup, ixWdbeVLocale)
  		{
  	jref = xchg->addJob(dbswdbe, this, jrefSup);
  
  	feedFCsiQst.tag = "FeedFCsiQst";
  	feedFCsiQst.appendIxSrefTitles(VecWdbeVQrystate::MNR, "ong", VecWdbeVQrystate::getTitle(VecWdbeVQrystate::MNR, ixWdbeVLocale));
  	feedFCsiQst.appendIxSrefTitles(VecWdbeVQrystate::OOD, "red", VecWdbeVQrystate::getTitle(VecWdbeVQrystate::OOD, ixWdbeVLocale));
  	feedFCsiQst.appendIxSrefTitles(VecWdbeVQrystate::SLM, "yel", VecWdbeVQrystate::getTitle(VecWdbeVQrystate::SLM, ixWdbeVLocale));
  	feedFCsiQst.appendIxSrefTitles(VecWdbeVQrystate::UTD, "grn", VecWdbeVQrystate::getTitle(VecWdbeVQrystate::UTD, ixWdbeVLocale));
  
  	qry = NULL;
  
  	// IP constructor.cust1 --- INSERT
  
  	xchg->addRefPreset(VecWdbeVPreset::PREWDBEREFSEL, jref, 0);
  
  	qry = new QryWdbeCmdMNController(xchg, dbswdbe, jref, ixWdbeVLocale);
  
  	// IP constructor.cust2 --- INSERT
  
  	set<uint> moditems;
  	refresh(dbswdbe, moditems);
  
  	xchg->addClstn(VecWdbeVCall::CALLWDBESTATCHG, jref, Clstn::VecVJobmask::IMM, 0, false, Arg(), 0, Clstn::VecVJactype::LOCK);
  
  	// IP constructor.cust3 --- INSERT
  
  };
  
  PnlWdbeCmdMNController::~PnlWdbeCmdMNController() {
  	// IP destructor.spec --- INSERT
  
  	// IP destructor.cust --- INSERT
  
  	xchg->removeJobByJref(jref);
  };
  
  // IP cust --- INSERT
  
  DpchEngWdbe* PnlWdbeCmdMNController::getNewDpchEng(
  			set<uint> items
  		) {
  	DpchEngWdbe* dpcheng = NULL;
  
  	if (items.empty()) {
  		dpcheng = new DpchEngWdbeConfirm(true, jref, "");
  	} else {
  		insert(items, DpchEngData::JREF);
  		dpcheng = new DpchEngData(jref, &continf, &feedFCsiQst, &statshr, &stgiac, &(qry->rst), &(qry->statshr), &(qry->stgiac), items);
  	};
  
  	return dpcheng;
  };
  
  void PnlWdbeCmdMNController::refresh(
  			DbsWdbe* dbswdbe
  			, set<uint>& moditems
  			, const bool unmute
  		) {
  	if (muteRefresh && !unmute) return;
  	muteRefresh = true;
  
  	ContInf oldContinf(continf);
  	StatShr oldStatshr(statshr);
  
  	// IP refresh --- BEGIN
  	// continf
  	continf.numFCsiQst = feedFCsiQst.getNumByIx(qry->ixWdbeVQrystate);
  
  	// statshr
  	statshr.ButViewAvail = evalButViewAvail(dbswdbe);
  	statshr.ButViewActive = evalButViewActive(dbswdbe);
  	statshr.ButAddAvail = evalButAddAvail(dbswdbe);
  	statshr.ButSubAvail = evalButSubAvail(dbswdbe);
  	statshr.ButSubActive = evalButSubActive(dbswdbe);
  
  	// IP refresh --- END
  	if (continf.diff(&oldContinf).size() != 0) insert(moditems, DpchEngData::CONTINF);
  	if (statshr.diff(&oldStatshr).size() != 0) insert(moditems, DpchEngData::STATSHR);
  
  	muteRefresh = false;
  };
  
  void PnlWdbeCmdMNController::updatePreset(
  			DbsWdbe* dbswdbe
  			, const uint ixWdbeVPreset
  			, const ubigint jrefTrig
  			, const bool notif
  		) {
  	// IP updatePreset --- BEGIN
  	set<uint> moditems;
  
  	if (ixWdbeVPreset == VecWdbeVPreset::PREWDBEREFCMD) {
  		recCmdRctr = WdbeRMCommandMController();
  
  		recCtr = WdbeMController();
  
  		xchg->addRefPreset(VecWdbeVPreset::PREWDBEREFSEL, jref, 0);
  
  		qry->stgiac.jnumFirstload = 1;
  
  		qry->rerun(dbswdbe);
  		refresh(dbswdbe, moditems);
  
  		if (notif) {
  			insert(moditems, {DpchEngData::STATSHRQRY, DpchEngData::STGIACQRY, DpchEngData::RST});
  			xchg->submitDpch(getNewDpchEng(moditems));
  		};
  	};
  	// IP updatePreset --- END
  };
  
  void PnlWdbeCmdMNController::handleRequest(
  			DbsWdbe* dbswdbe
  			, ReqWdbe* req
  		) {
  	if (req->ixVBasetype == ReqWdbe::VecVBasetype::CMD) {
  		reqCmd = req;
  
  		if (req->cmd == "cmdset") {
  
  		} else {
  			cout << "\tinvalid command!" << endl;
  		};
  
  		if (!req->retain) reqCmd = NULL;
  
  	} else if (req->ixVBasetype == ReqWdbe::VecVBasetype::DPCHAPP) {
  		if (req->dpchapp->ixWdbeVDpch == VecWdbeVDpch::DPCHAPPWDBEINIT) {
  			handleDpchAppWdbeInit(dbswdbe, (DpchAppWdbeInit*) (req->dpchapp), &(req->dpcheng));
  
  		} else if (req->dpchapp->ixWdbeVDpch == VecWdbeVDpch::DPCHAPPWDBECMDMNCONTROLLERDATA) {
  			DpchAppData* dpchappdata = (DpchAppData*) (req->dpchapp);
  
  			if (dpchappdata->has(DpchAppData::STGIAC)) {
  				handleDpchAppDataStgiac(dbswdbe, &(dpchappdata->stgiac), &(req->dpcheng));
  			} else if (dpchappdata->has(DpchAppData::STGIACQRY)) {
  				handleDpchAppDataStgiacqry(dbswdbe, &(dpchappdata->stgiacqry), &(req->dpcheng));
  			};
  
  		} else if (req->dpchapp->ixWdbeVDpch == VecWdbeVDpch::DPCHAPPWDBECMDMNCONTROLLERDO) {
  			DpchAppDo* dpchappdo = (DpchAppDo*) (req->dpchapp);
  
  			if (dpchappdo->ixVDo != 0) {
  				if (dpchappdo->ixVDo == VecVDo::BUTVIEWCLICK) {
  					handleDpchAppDoButViewClick(dbswdbe, &(req->dpcheng));
  				} else if (dpchappdo->ixVDo == VecVDo::BUTADDCLICK) {
  					handleDpchAppDoButAddClick(dbswdbe, &(req->dpcheng));
  				} else if (dpchappdo->ixVDo == VecVDo::BUTSUBCLICK) {
  					handleDpchAppDoButSubClick(dbswdbe, &(req->dpcheng));
  				} else if (dpchappdo->ixVDo == VecVDo::BUTREFRESHCLICK) {
  					handleDpchAppDoButRefreshClick(dbswdbe, &(req->dpcheng));
  				};
  
  			};
  
  		};
  	};
  };
  
  void PnlWdbeCmdMNController::handleDpchAppWdbeInit(
  			DbsWdbe* dbswdbe
  			, DpchAppWdbeInit* dpchappwdbeinit
  			, DpchEngWdbe** dpcheng
  		) {
  	*dpcheng = getNewDpchEng({DpchEngData::ALL});
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDataStgiac(
  			DbsWdbe* dbswdbe
  			, StgIac* _stgiac
  			, DpchEngWdbe** dpcheng
  		) {
  	set<uint> diffitems;
  	set<uint> moditems;
  
  	diffitems = _stgiac->diff(&stgiac);
  	// IP handleDpchAppDataStgiac --- INSERT
  	insert(moditems, DpchEngData::STGIAC);
  	*dpcheng = getNewDpchEng(moditems);
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDataStgiacqry(
  			DbsWdbe* dbswdbe
  			, QryWdbeCmdMNController::StgIac* _stgiacqry
  			, DpchEngWdbe** dpcheng
  		) {
  	set<uint> diffitems;
  	set<uint> moditems;
  
  	diffitems = _stgiacqry->diff(&(qry->stgiac));
  
  	WdbeQCmdMNController* recSelNew = NULL;
  
  	WdbeRMCommandMController* _recCmdRctr = NULL;
  	WdbeMController* _recCtr = NULL;
  
  	if (!diffitems.empty()) {
  		muteRefresh = true;
  
  		qry->stgiac = *_stgiacqry;
  
  		if (has(diffitems, QryWdbeCmdMNController::StgIac::JNUM)) recSelNew = qry->getRecByJnum(_stgiacqry->jnum);
  
  		if (!has(diffitems, QryWdbeCmdMNController::StgIac::JNUM) || (diffitems.size() > 1)) {
  			qry->rerun(dbswdbe);
  			insert(moditems, {DpchEngData::STATSHRQRY, DpchEngData::RST});
  		};
  
  		if (has(diffitems, QryWdbeCmdMNController::StgIac::JNUM)) {
  			if (!recSelNew) recSelNew = qry->getRecByJnum(_stgiacqry->jnum);
  
  			recCmdRctr = WdbeRMCommandMController();
  
  			recCtr = WdbeMController();
  
  			if (recSelNew) {
  				if (dbswdbe->tblwdbermcommandmcontroller->loadRecByRef(recSelNew->ref, &_recCmdRctr)) {
  					recCmdRctr = *_recCmdRctr;
  					delete _recCmdRctr;
  				};
  				if (dbswdbe->tblwdbemcontroller->loadRecByRef(recSelNew->mref, &_recCtr)) {
  					recCtr = *_recCtr;
  					delete _recCtr;
  				};
  			};
  
  			xchg->addRefPreset(VecWdbeVPreset::PREWDBEREFSEL, jref, ((recSelNew) ? recSelNew->ref : 0));
  			qry->refreshJnum();
  		};
  
  		refresh(dbswdbe, moditems, true);
  	};
  
  	insert(moditems, DpchEngData::STGIACQRY);
  	*dpcheng = getNewDpchEng(moditems);
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDoButViewClick(
  			DbsWdbe* dbswdbe
  			, DpchEngWdbe** dpcheng
  		) {
  	ubigint jrefNew = 0;
  	string sref;
  
  	uint ixPre = xchg->getIxPreset(VecWdbeVPreset::PREWDBEIXPRE, jref);
  	ubigint refPre = ((ixPre) ? xchg->getRefPreset(ixPre, jref) : 0);
  
  	ubigint refCvr = xchg->getRefPreset(VecWdbeVPreset::PREWDBEREFCVR, jref);
  
  	if (statshr.ButViewAvail && statshr.ButViewActive) {
  		if (xchg->getIxPreset(VecWdbeVPreset::PREWDBEIXCRDACCMOD, jref)) if ((dbswdbe->getIxWSubsetByRefWdbeMModule(recCtr.refWdbeMModule) & VecWdbeWMModuleSubset::SBSWDBEBMMODULEMOD) != 0) if (ixPre == VecWdbeVPreset::PREWDBEREFUNT) {
  			sref = "CrdWdbeMod";
  			xchg->triggerIxRefSrefIntvalToRefCall(dbswdbe, VecWdbeVCall::CALLWDBECRDOPEN, jref, ixPre, refPre, sref, [&](){ubigint ref = 0; dbswdbe->loadRefBySQL("SELECT ref FROM TblWdbeMModule WHERE refWdbeMController = " + to_string(recCtr.ref), ref); return ref;}(), jrefNew);
  		};
  		if (jrefNew == 0) {
  			if (xchg->getIxPreset(VecWdbeVPreset::PREWDBEIXCRDACCMOD, jref)) if ((dbswdbe->getIxWSubsetByRefWdbeMModule(recCtr.refWdbeMModule) & VecWdbeWMModuleSubset::SBSWDBEBMMODULEMOD) != 0) if (refCvr != 0) {
  				sref = "CrdWdbeMod";
  				xchg->triggerIxRefSrefIntvalToRefCall(dbswdbe, VecWdbeVCall::CALLWDBECRDOPEN, jref, VecWdbeVPreset::PREWDBEREFCVR, refCvr, sref, [&](){ubigint ref = 0; dbswdbe->loadRefBySQL("SELECT ref FROM TblWdbeMModule WHERE refWdbeMController = " + to_string(recCtr.ref), ref); return ref;}(), jrefNew);
  			};
  		};
  		if (jrefNew == 0) {
  			if (xchg->getIxPreset(VecWdbeVPreset::PREWDBEIXCRDACCMTP, jref)) if ((dbswdbe->getIxWSubsetByRefWdbeMModule(recCtr.refWdbeMModule) & VecWdbeWMModuleSubset::SBSWDBEBMMODULEMTP) != 0) {
  				sref = "CrdWdbeMtp";
  				xchg->triggerIxRefSrefIntvalToRefCall(dbswdbe, VecWdbeVCall::CALLWDBECRDOPEN, jref, 0, 0, sref, [&](){ubigint ref = 0; dbswdbe->loadRefBySQL("SELECT ref FROM TblWdbeMModule WHERE refWdbeMController = " + to_string(recCtr.ref), ref); return ref;}(), jrefNew);
  			};
  		};
  
  		if (jrefNew == 0) *dpcheng = new DpchEngWdbeConfirm(false, 0, "");
  		else *dpcheng = new DpchEngWdbeConfirm(true, jrefNew, sref);
  	};
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDoButAddClick(
  			DbsWdbe* dbswdbe
  			, DpchEngWdbe** dpcheng
  		) {
  	// IP handleDpchAppDoButAddClick --- INSERT
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDoButSubClick(
  			DbsWdbe* dbswdbe
  			, DpchEngWdbe** dpcheng
  		) {
  	// IP handleDpchAppDoButSubClick --- INSERT
  };
  
  void PnlWdbeCmdMNController::handleDpchAppDoButRefreshClick(
  			DbsWdbe* dbswdbe
  			, DpchEngWdbe** dpcheng
  		) {
  	set<uint> moditems;
  
  	muteRefresh = true;
  
  	qry->rerun(dbswdbe, false);
  
  	refresh(dbswdbe, moditems, true);
  
  	insert(moditems, {DpchEngData::STATSHRQRY, DpchEngData::STGIACQRY, DpchEngData::RST});
  	*dpcheng = getNewDpchEng(moditems);
  };
  
  void PnlWdbeCmdMNController::handleCall(
  			DbsWdbe* dbswdbe
  			, Call* call
  		) {
  	if (call->ixVCall == VecWdbeVCall::CALLWDBESTATCHG) {
  		call->abort = handleCallWdbeStatChg(dbswdbe, call->jref);
  	};
  };
  
  bool PnlWdbeCmdMNController::handleCallWdbeStatChg(
  			DbsWdbe* dbswdbe
  			, const ubigint jrefTrig
  		) {
  	bool retval = false;
  	// IP handleCallWdbeStatChg --- BEGIN
  
  	set<uint> moditems;
  
  	if (jrefTrig == qry->jref) {
  		if (!muteRefresh) {
  			refresh(dbswdbe, moditems);
  			if (qry->ixWdbeVQrystate == VecWdbeVQrystate::UTD) insert(moditems, {DpchEngData::STATSHRQRY, DpchEngData::STGIACQRY, DpchEngData::RST});
  			if (!moditems.empty()) xchg->submitDpch(getNewDpchEng(moditems));
  		};
  	};
  
  	// IP handleCallWdbeStatChg --- END
  	return retval;
  };
  