如何在两个表单之间传递多个记录?
How to pass more than one record between two forms?
我想在两个表单之间传递不止一条记录。用户打开 Form-A,选择多条记录,然后单击打开 Form-B 的按钮。
在 Form-B 中有两个(或更多)StringEdit
控件,它们应该显示所选记录中的值。
我知道如何只传递一条记录,为此我在 Form-B 的方法中使用以下代码:
if (element.args().parmEnumType() == enumNum(NoYes)
&& element.args().parmEnum() == NoYes::Yes)
{
myTable = element.args().record();
stringEdit.text(myTable.Field);
}
我应该如何更改我的代码,以便我可以将另一个 StringEdit
控件的文本设置为用户选择的下一条记录的字段值?
为此,您可以使用 args
传递记录,您需要在 Form-A 中准备这些记录,如下所示(以 SalesTable 为例);
int recordsCount;
SalesTable salesTable;
container con;
Args args = newArgs();
// gets the total records selected
recordsCount = salesTable_ds.recordsMarked().lastIndex();
salesTable = salesTable_ds.getFirst(1);
while(salesTable)
{
// storing recid of selected record in container
con = conIns(con,1, salesTable.RecId);
salesTable = SampleTable_ds.getNext(); // moves to next record
}
// passing container converted to string
args.parm(con2Str(con,','));
然后在您的 Form-B 上,您需要覆盖 init()
方法来读取您创建的参数,
为了从收件人中检索传递的参数。如图所示覆盖新表单的 init() 方法
public void init()
{
container con;
int i;
super();
// string to container
con = str2con(element.args().parm(),'','');
// for sorting
for(i = 1;i<= conLen(con) ;i++)
{
salesTable_ds.query().dataSourceTable(Tablenum(SalesTable)).addRange(fieldNum(SalesTable,RecId)).value(SysQuery::value(conPeek(con,i)));
}
}
希望对您有所帮助。
取自Ax-Forum
这通常意味着遍历 Form-A
中的选定记录并更改 Form-B
中的查询。
遍历选定记录的惯用方法涉及 for
循环和数据源的 getFirst
和 getNext
方法:
SalesLine sl;
FormDataSourcs ds = _salesLine.dataSource();
for (sl = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor(); sl; sl = ds.getNext())
{
//Do your thing, add a query range
}
MultiSelectionHelper class 在这里可能会有用,因为它的作用是:
public void init()
{
MultiSelectionHelper ms;
super();
if (element.args() && element.args().caller() && element.args().record())
{
this.query().dataSourceTable(tableNum(SalesLine)).clearDynalinks();
ms = MultiSelectionHelper::createFromCaller(element.args().caller());
ms.createQueryRanges(this.query().dataSourceTable(tablenum(SalesLine)), fieldstr(SalesLine, InventTransId));
}
}
我想在两个表单之间传递不止一条记录。用户打开 Form-A,选择多条记录,然后单击打开 Form-B 的按钮。
在 Form-B 中有两个(或更多)StringEdit
控件,它们应该显示所选记录中的值。
我知道如何只传递一条记录,为此我在 Form-B 的方法中使用以下代码:
if (element.args().parmEnumType() == enumNum(NoYes)
&& element.args().parmEnum() == NoYes::Yes)
{
myTable = element.args().record();
stringEdit.text(myTable.Field);
}
我应该如何更改我的代码,以便我可以将另一个 StringEdit
控件的文本设置为用户选择的下一条记录的字段值?
为此,您可以使用 args
传递记录,您需要在 Form-A 中准备这些记录,如下所示(以 SalesTable 为例);
int recordsCount;
SalesTable salesTable;
container con;
Args args = newArgs();
// gets the total records selected
recordsCount = salesTable_ds.recordsMarked().lastIndex();
salesTable = salesTable_ds.getFirst(1);
while(salesTable)
{
// storing recid of selected record in container
con = conIns(con,1, salesTable.RecId);
salesTable = SampleTable_ds.getNext(); // moves to next record
}
// passing container converted to string
args.parm(con2Str(con,','));
然后在您的 Form-B 上,您需要覆盖 init()
方法来读取您创建的参数,
为了从收件人中检索传递的参数。如图所示覆盖新表单的 init() 方法
public void init()
{
container con;
int i;
super();
// string to container
con = str2con(element.args().parm(),'','');
// for sorting
for(i = 1;i<= conLen(con) ;i++)
{
salesTable_ds.query().dataSourceTable(Tablenum(SalesTable)).addRange(fieldNum(SalesTable,RecId)).value(SysQuery::value(conPeek(con,i)));
}
}
希望对您有所帮助。
取自Ax-Forum
这通常意味着遍历 Form-A
中的选定记录并更改 Form-B
中的查询。
遍历选定记录的惯用方法涉及 for
循环和数据源的 getFirst
和 getNext
方法:
SalesLine sl;
FormDataSourcs ds = _salesLine.dataSource();
for (sl = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor(); sl; sl = ds.getNext())
{
//Do your thing, add a query range
}
MultiSelectionHelper class 在这里可能会有用,因为它的作用是:
public void init()
{
MultiSelectionHelper ms;
super();
if (element.args() && element.args().caller() && element.args().record())
{
this.query().dataSourceTable(tableNum(SalesLine)).clearDynalinks();
ms = MultiSelectionHelper::createFromCaller(element.args().caller());
ms.createQueryRanges(this.query().dataSourceTable(tablenum(SalesLine)), fieldstr(SalesLine, InventTransId));
}
}