Tuesday, October 20, 2009

Axapta : Enable/Disable Dialog Control at runtime

วิธี Enable/Disable หรือ Dialog Control ในขณะ runtime ทำได้โดย ดังนี้
disable_runtime_dialog_control
1.classDeclaration
class SCI_Costing extends RunBase
{
FormStringControl SalesIdCtrl, ItemIdCtrl;
FormCheckBoxControl bAllCtrl;

SalesId salesId;
ItemId itemId;
NoYes bAll;

#define.CurrentVersion(1)

#localmacro.CurrentList
salesId,
itemId,
bAll
#endmacro
}


2.สร้าง dialog แบบอนุญาตให้ update control ได้ โดยใช้ dialog.allowUpdateOnSelectCtrl(true)

protected Object dialog(Dialog dialog, boolean forceOnClient)
{
DialogRunBase ret;
;
ret = super(dialog, forceOnClient);
ret.caption('Costing report by order');
ret.allowUpdateOnSelectCtrl(true); //อนุญาตให้ update control ได้

SalesIdCtrl = ret.formBuildDesign().addControl(FormControlType::String,'SalesId');
SalesIdCtrl.extendedDataType(extendedTypeNum('SalesId'));

bAllCtrl = ret.formBuildDesign().addControl(FormControlType::CheckBox,'bAll');
bAllCtrl.label('All');

ItemIdCtrl = ret.formBuildDesign().addControl(FormControlType::String,'ItemId');
ItemIdCtrl.extendedDataType(extendedTypeNum('ItemId'));

return ret;
}

3.เซ็ตให้ control สามารถ override method ตอน runtime ได้
public void dialogPostRun(DialogRunbase dialog)
{
;
super(dialog);
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
SalesIdCtrl = dialog.dialogForm().formRun().design().controlName('SalesId');
ItemIdCtrl = dialog.dialogForm().formRun().design().controlName('ItemId');
bAllCtrl = dialog.dialogForm().formRun().design().controlName('bAll');
}

4.ใช้ method dialogSelectCtrl เพื่อดำเนินการ update control ซึ่งในที่นี้ก็คือการ enable/disable ItemId
public void dialogSelectCtrl()
{
;
if (bAllCtrl.value()== 0)
{
ItemIdCtrl.allowEdit(true);
}
else
{
ItemIdCtrl.allowEdit(false);
}
}

1 comment:

Ebbes Nørderi (Ebbes Nerdery) » Blog Archive » Axapta : Enable/Disable Dialog Control at runtime said...

[…] Found here: http://www.komkid.net/2009/10/axapta-enabledisable-dialog-control-at-runtime/ […]