比如要做一张杂项收费的报表,需要查看销售订单的杂项收费情况以及对应的订单号.杂项收费可能关联到客户发票的主表CustInvoiceJour,也可能关联到明细表CustInvoceTrans.
这种情况下就必须分别构造两个不同的Query
1.如果杂项收费是关联到主表的,则只需要将MarkUpTrans和CustInvoiceJournal关联,
2.如果杂项收费是关联到从表的,则需要将MarkUpTrans,CustInvoiceTrans和CustInvoiceJournal三个表关联.
由于是自己构造的Query,用户在Dialog处用select选择的Range的值不会加到Query上,必须写代码关联过来,下面的代码显示了关联的过程,DataSource按照情况2构造.
QueryRun BuildDetailQueryRun()
{
QueryRun qrDetail;
QueryRun qrOriginal;
Query q;
QueryBuildDataSource qbdsMarkUpTransOriginal;
QueryBuildDataSource qbdsInvoiceJournalOriginal;
QueryBuildDataSource qbdsInvoiceTransOriginal;
QueryBuildDataSource qbdsMarkUpTrans;
QueryBuildDataSource qbdsInvoiceJournal;
QueryBuildDataSource qbdsInvoiceTrans;
int i;
;
q = new Query();
qbdsMarkUpTrans = q.addDataSource(tableNum(markUpTrans));
qbdsInvoiceTrans = qbdsMarkUpTrans.addDataSource(tableNum(CustInvoiceTrans));
qbdsInvoiceTrans.relations(true);
qbdsInvoiceJournal = qbdsInvoiceTrans.addDataSource(tableNum(CustInvoiceJour));
qbdsInvoiceJournal.relations(true);
qrOriginal = new QueryRun(this);
qbdsMarkUpTransOriginal = qrOriginal.query().dataSourceTable(tableNum(markUpTrans));
for( i = 1; i <= qbdsMarkUpTransOriginal.rangeCount();i++)
qbdsMarkUpTrans.addRange(fieldName2Id(tableNum(markUpTrans),qbdsMarkUpTransOriginal.range(i).name())).value(qbdsMarkUpTransOriginal.range(i).value());
qbdsInvoiceJournalOriginal = qrOriginal.query().dataSourceTable(tableNum(CustInvoiceJour));
for( i =1 ;i<= qbdsInvoiceJournalOriginal.rangeCount();i++)
qbdsInvoiceJournal.addRange(fieldName2Id(tableNum(custInvoiceJour),qbdsInvoiceJournalOriginal.range(i).name())).value(qbdsInvoiceJournalOriginal.range(i).value());
qbdsInvoiceTransOriginal = qrOriginal.query().dataSourceTable(tableNum(CustInvoiceTrans));
for( i = 1; i<=qbdsInvoiceTransOriginal.rangeCount();i++)
qbdsInvoiceTrans.addRange(fieldName2Id(tableNum(custInvoiceTrans),qbdsInvoiceTransOriginal.range(i).name())).value(qbdsInvoiceTransOriginal.range(i).value());
qrDetail = new QueryRun(q);
return qrDetail;
}
{
QueryRun qrDetail;
QueryRun qrOriginal;
Query q;
QueryBuildDataSource qbdsMarkUpTransOriginal;
QueryBuildDataSource qbdsInvoiceJournalOriginal;
QueryBuildDataSource qbdsInvoiceTransOriginal;
QueryBuildDataSource qbdsMarkUpTrans;
QueryBuildDataSource qbdsInvoiceJournal;
QueryBuildDataSource qbdsInvoiceTrans;
int i;
;
q = new Query();
qbdsMarkUpTrans = q.addDataSource(tableNum(markUpTrans));
qbdsInvoiceTrans = qbdsMarkUpTrans.addDataSource(tableNum(CustInvoiceTrans));
qbdsInvoiceTrans.relations(true);
qbdsInvoiceJournal = qbdsInvoiceTrans.addDataSource(tableNum(CustInvoiceJour));
qbdsInvoiceJournal.relations(true);
qrOriginal = new QueryRun(this);
qbdsMarkUpTransOriginal = qrOriginal.query().dataSourceTable(tableNum(markUpTrans));
for( i = 1; i <= qbdsMarkUpTransOriginal.rangeCount();i++)
qbdsMarkUpTrans.addRange(fieldName2Id(tableNum(markUpTrans),qbdsMarkUpTransOriginal.range(i).name())).value(qbdsMarkUpTransOriginal.range(i).value());
qbdsInvoiceJournalOriginal = qrOriginal.query().dataSourceTable(tableNum(CustInvoiceJour));
for( i =1 ;i<= qbdsInvoiceJournalOriginal.rangeCount();i++)
qbdsInvoiceJournal.addRange(fieldName2Id(tableNum(custInvoiceJour),qbdsInvoiceJournalOriginal.range(i).name())).value(qbdsInvoiceJournalOriginal.range(i).value());
qbdsInvoiceTransOriginal = qrOriginal.query().dataSourceTable(tableNum(CustInvoiceTrans));
for( i = 1; i<=qbdsInvoiceTransOriginal.rangeCount();i++)
qbdsInvoiceTrans.addRange(fieldName2Id(tableNum(custInvoiceTrans),qbdsInvoiceTransOriginal.range(i).name())).value(qbdsInvoiceTransOriginal.range(i).value());
qrDetail = new QueryRun(q);
return qrDetail;
}
代码很简单也就不解释了.