宏实现动态SELECT语句(同事说明报价单注释的逻辑)

在报价单上,我们可以附加“注释”,而在附加注释时我们可以为他添加限制‘INTERNAL或者EXTERNAL’,而在打印报价单时,系统会调用到方法:

void printDocumentHeader()
{
    printDocuHeader = true;
    if ((custFormletterDocument.DocuOnQuotation == DocuOnFormular::Head) ||
        (custFormletterDocument.DocuOnQuotation == DocuOnFormular::All))
        Docu::send(this, DocuRefSearch::newTypeIdAndRestriction(custQuotationJour,
                                                                custFormletterDocument.DocuTypeQuotation,
                                                                DocuRestriction::External));
    printDocuHeader = false;
}

来决定是否打出注释,

Docu::send(this, DocuRefSearch::newTypeIdAndRestriction(custQuotationJour,
                                                                custFormletterDocument.DocuTypeQuotation,
                                                                DocuRestriction::External));

该方法传递external作为参数:(DocuRefSearch类)

static DocuRefSearch newTypeIdAndRestriction(
    Common          common,
    DocuTypeId      docuTypeId,
    DocuRestriction restriction
    )
{
    DocuRefSearch   docuRefSearch = DocuRefSearch::construct();
;
    docuRefSearch.parmCommon(common);
    docuRefSearch.parmDocuTypeId(docuTypeId);
    docuRefSearch.parmAllRestrictions(false);
    docuRefSearch.parmRestriction(restriction);
    docuRefSearch.init();

    return docuRefSearch;
}
注意docuRefSearch.parmAllRestrictions(false);始终传递FALSE,然后docuRefSearch.parmRestriction(restriction);传递的始终是EXTERNAL,

 docuRefSearch.init();会调用:SysSearchBase的方法:
void init()
{
    this.search();
}

而这个search方法则会去调用DocuRefSearch类的:

protected void search()
{

    #localmacro.default
        select noFetch docuRef
            index RefIdx            // Not hint, cause of the order
            where docuRef.refCompanyId  == common.dataAreaId    &&
                  docuRef.refTableId    == common.tableId       &&
                  docuRef.refRecId      == common.recId         &&
                  (docuRef.typeId        == docuTypeId  ||
                   ! docuTypeId
                  )
    #endmacro

    if (allRestrictions)
        #default;
    else
        #default &&
        docuRef.Restriction == restriction;
}

这里就是最有意思的地方了,docuRef是在前边已经声明的一个DocuRef表的实例,它会记录所有的“注释”,这里先更具我们所掌握的记录去查找对应的记录,如果在添加注释时将其设为internal,那么注意:

先前的docuRefSearch.parmAllRestrictions(false);决定了if (allRestrictions)不成立,所以会走

else
        #default &&
        docuRef.Restriction == restriction;
注意这里它将宏语句和&&docuRef.Restriction == restriction;进行链接,形成实际执行的查询语句,,由于我们添加注释时使用了INTERNAL决定了你查不到。

——————————————————————————————————————————

这里是我的一个测试:

我的INVENTDIM表中有一条记录,inventdimid=00001_060,inventlocationid="gw",现在我先按以下语句执行:

static void Job6(Args _args)
{
     InventDim  inventDim;
     #localmacro.default
        select inventDim
            where inventDim.inventDimId == "00001_060"
    #endmacro

    if (false)
        #default;
    else
        #default&&
        inventDim.inventLocationId == "MW" ;
    if(inventDim)
    {
        print inventDim.inventDimId;
    }
    else
    {
        print "...";
    }
    pause;
}

结果是: “。。。”

static void Job6(Args _args)
{
     InventDim  inventDim;
     #localmacro.default
        select inventDim
            where inventDim.inventDimId == "00001_060"
    #endmacro

    if (false)
        #default;
    else
        #default&&
        inventDim.inventLocationId == "GW" ;
    if(inventDim)
    {
        print inventDim.inventDimId;
    }
    else
    {
        print "...";
    }
    pause;
}

结果是: 00001_060:GW

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值