一、MultiSelectionHelper class
MultiSelectionHelper selectionHelper;
ProdTable localProdTable;
FormRun fr;
;
pro
dSet = new Set(Types::String);
if (_args && _args.caller() && _args.dataset() == TableNum(ProdTable))
{
fr = _args.caller();
fds= _args.record().dataSource();
selectionHelper = MultiSelectionHelper::createFromCaller(fr);
for (localProdTable = selectionHelper.getFirst();
localProdTable;
localProdTable = selectionHelper.getNext())
{
prodSet.add(localProdTable.ProdId);
if (localProdTable.createdBy != curUserId())
icount++;
if (localProdTable.ProdStatus > ProdStatus::StartedUp)
jcount++;
}
}
Second, a plurality of data and the unselected Form
Adopt a consistent approach and system:
Prerequisite: Table Name: DavMultiSelect
In the form of the table is used as data source, is named DavMultiSelect
(1) declare a table variable table DavMultiSelect
(2) for loop traversing the selected record
(3) Processing in each of the selected records for loop
DavMultiSelect tmp;
;
for(tmp = DavMultiSelect_DS.getFirst(true)?DavMultiSelect_DS.getFirst(true):DavMultiSelect_DS.cursor();tmp;tmp = DavMultiSelect_DS.getNext())
{
// Here processing each record
print tmp.Field1;
}
About the method:
(1)FormDataSource.getFirst([int mark, boolean fetchAhead])
public Common getFirst([int mark, boolean fetchAhead])
parameter:
mark: decided to return to a recording mark or the identified first. If Mark is not zero, the piece was identified by Mark record is returned, then return calls getNext other selected records.
When a plurality of records in the grid is selected, the record set is identified as mark = 1.
fetchAhead: If false, only to be returned cach up record; if true, is not cach up records will be added to cach then look first, and then return all the selected records. If you selected a large set of records, it can be time consuming when set to true.
(2)FormDataSource.markRecord(anty record[,int mark])
parameter:
record: To record mark of
mark: tag value
If you select a record, and then calls (with the extension above example):
DavMultiSelect _DS.markRecord(DavMultiSelect _DS.cursor());
tmp = DavMultiSelect _DS.getFirst(2,true);
这个时候,tmp和DavMultiSelect_DS.cursor是同一条记录
(3)FormDataSource.getNext()
public Common getNext()
会返回符合在getFirst中设置的过滤原则的下一条记录。
反选
注意:
(1)使用FormDataSource.getFirst([int mark,boolean fetchAhead]),如果参数mark=0的话,使用循环会返回当前DataSource的所有记录。
(2)如果FormDataSource上的记录被mark为大于零的任何整数,在element.redraw()后都会处于选中状态。
代码如下:
void clicked()
{
DavQuery common;
Map map;
;
map = new Map(Types::Int64,Types::Int64);
for(common = DavQuery_DS.getFirst(true) ? DavQuery_DS.getFirst(true) : DavQuery_DS.cursor();
common;
common = DavQuery_DS.getNext())
{
if(!map.exists(common.RecId))
map.insert(common.RecId,common.RecId);
DavQuery_Ds.markRecord(common,0);
}
for(common = DavQuery_DS.getFirst(0) ? DavQuery_DS.getFirst(0) : DavQuery_DS.cursor();
common;
common = DavQuery_DS.getNext())
{
if(!map.exists(common.RecId))
{
DavQuery_DS.markRecord(common,1);
}
}
super();
element.redraw();
}