vendredi 10 juin 2011

How to make a lookup from using two DataSources

For example you make two grids in your form having each one a dataSource 

in the init of your form :

void init()
{;

    super();

    this.setSelectMode();
}

int the  setSelectMode method of  your form

void setSelectMode()
{
    switch (ctrlTab.tab())
    {
        case 0,1:
            this.selectMode(EmplTable_EmplId);
            EmplTable_EmplId.setFocus();
            break;
        case 2:
            this.selectMode(Payroll_EmplId);
            Payroll_EmplId.setFocus();
            break;
    }
}

In the init method of your first dataSource 

void init()
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    PayrollEmployee         payrollEmployee;
    PayrollEmplId           payrollEmplId;
    ;

    queryBuildDataSource = query.addDataSource(tablenum(EmplTable));

    queryBuildRange = queryBuildDataSource.addRange(fieldnum(EmplTable, EmplId));
    select emplId from emplTable notexists join payrollEmployee
     where emplTable.EmplId == payrollEmployee.EmplId;
    payrollEmplId = emplTable.EmplId;
    queryBuildRange.value(queryValue(payrollEmplId));

    this.query(query);
}

 In the executeQuery method of this dataSource

void executeQuery()
{
    PayrollEmployee             payrollEmployee;
    ;

     Select emplTable  notexists join payrollEmployee
      where emplTable.EmplId == payrollEmployee.EmplId;
}

In the second init method of your dataSource 

void init()
{
    Query   query = new Query();
    ;
    super();

    query.addDataSource(tablenum(EmplTable));

    this.query(query);
}

Here you can dowload the example of the lookup Form.

Aucun commentaire:

Enregistrer un commentaire